VMware Cloud Community
pamiller21
Enthusiast
Enthusiast

SDRS Automation Level

I am trying to find a way in powercli to change the Storage DRS Automation Level to the Default (Fully Automated) on all my VMs.

 

$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]::FullyAutomated
$spec.VmConfigSpec += $vmSpec
}
$srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
}

0 Kudos
5 Replies
LucD
Leadership
Leadership

And what is the problem with this code?


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

0 Kudos
pamiller21
Enthusiast
Enthusiast

There is no error, but the VMs are not changing status to the Default

0 Kudos
LucD
Leadership
Leadership

The enum is not correct, that should be

$vmSpec.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated

This only changes the VMs for which there is already a VM Override and provided that Override is set to manual.
That code will not create new VM Overrides entries.


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

0 Kudos
pamiller21
Enthusiast
Enthusiast

Ah ok, I need to learn how to remove the overrides at all.

0 Kudos
LucD
Leadership
Leadership

You could do

$srmMgr = Get-View StorageResourceManager

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

    $dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig |
    ForEach-Object -Process {
        $vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec
        $vmSpec.Operation = [VMware.Vim.ArrayUpdateOperation]::Remove
        $vmSpec.RemoveKey = $_.Vm
        $spec.VmConfigSpec += $vmSpec
    }
    $srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef, $spec, $true)
}


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

0 Kudos