VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

SDRS Report/Enable

I have had a report running for any VM not set to the default of automatic, but it doesn't seem to be working and my script to enable the automatic SDRS isn't either.  No errors appear though.  Here are my scripts:

Enable SDRS:
$si = Get-View ServiceInstance
$srmMgr = Get-View -Id $si.Content.StorageResourceManager

foreach($dsc in Get-DatastoreCluster){
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{!$_.Enabled})){
$vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
$vmSpec.Info = $vm
$vmSpec.Info.Enabled = $true
$spec.VmConfigSpec += $vmSpec
}
$srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}

Report SDRS:

#############################
# Variables #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="/var/www/SDRS/SDRS-$date.htm"

#############################
# Content #
#############################
$report = foreach($dsc in Get-DatastoreCluster){
$defaultVM = $dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.PodConfig.DefaultVmBehavior
foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{!$_.Enabled})){
Get-View -Id $vm.Vm -Property Name |
Select @{N='DSC';E={$dsc.Name}},
Name,
@{N='Enabled';E={$vm.Enabled}},
@{N='Behavior';E={
if($vm.Behavior){$vm.Behavior}
else{"Default ($($defaultVM))"}
}}
}
}
#############################
# Add Text to the HTML file #
#############################
$report | ConvertTo-Html -title "VMware Hardware Version" -body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

Invoke-Item -Path $filelocation

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This seems to work for me.
The only issue might be that it does say 'Automated' for the VMs, but it will not say Default.
For that option, you will have to disable/enable SDRS

$si = Get-View ServiceInstance
$srmMgr = Get-View -Id $si.Content.StorageResourceManager

foreach($dsc in Get-DatastoreCluster){
    $spec = New-Object VMware.Vim.StorageDrsConfigSpec

    foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{$_.Behavior -eq [VMware.Vim.StorageDrsPodConfigInfoBehavior]::manual})){
        $vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
        $vmSpec.Operation = [VMware.Vim.ArrayUpdateOperation]::edit
        $vmSpec.Info = $vm
        $vmSpec.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated

        $spec.VmConfigSpec += $vmSpec
    }
    $srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

I'm not sure what exactly you are trying to do.
All VMs that do not appear in the VM Override window, are reported (since their Enabled property is empty).

When I run you second script, the VMs do appear in the VM Override window.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

Its not that they are in the window its some VMs will turn their automation levels to manual over time (probably due to storage migrations).  The script should change it from manual to automatic again.  Here is a screenshot that might help explain what I am seeing.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik that is the Behavior property, not the Enabled property.
It accepts automated or manual.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

Sorry not sure how to alter it to change that property

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

I experimented around, but not getting much luck on this.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

To make sure I get what you are trying to do.
In that screenshot earlier, it is the 1st VM that you want to set to Default (Fully Automated)?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

Correct!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This seems to work for me.
The only issue might be that it does say 'Automated' for the VMs, but it will not say Default.
For that option, you will have to disable/enable SDRS

$si = Get-View ServiceInstance
$srmMgr = Get-View -Id $si.Content.StorageResourceManager

foreach($dsc in Get-DatastoreCluster){
    $spec = New-Object VMware.Vim.StorageDrsConfigSpec

    foreach($vm in ($dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where{$_.Behavior -eq [VMware.Vim.StorageDrsPodConfigInfoBehavior]::manual})){
        $vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
        $vmSpec.Operation = [VMware.Vim.ArrayUpdateOperation]::edit
        $vmSpec.Info = $vm
        $vmSpec.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated

        $spec.VmConfigSpec += $vmSpec
    }
    $srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos