Automation

 View Only
  • 1.  SDRS Automation Level

    Posted May 05, 2022 05:55 PM

    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)
    }



  • 2.  RE: SDRS Automation Level

    Posted May 05, 2022 06:39 PM

    And what is the problem with this code?



  • 3.  RE: SDRS Automation Level

    Posted May 05, 2022 07:14 PM

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



  • 4.  RE: SDRS Automation Level

    Posted May 05, 2022 08:14 PM

    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.



  • 5.  RE: SDRS Automation Level

    Posted May 07, 2022 02:01 AM

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



  • 6.  RE: SDRS Automation Level

    Posted May 07, 2022 06:26 AM

    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)
    }