VMware Cloud Community
pamiller21
Enthusiast
Enthusiast

SDRS Enable

Hey all,

I have got a script that I run once a week to enable SDRS on all my VMs, because during SvMotions you have to disable it, but I do want it enabled for balance reasons.  This script I run works great, but times have changed and now I need to have a few VMs stay put on a certain datastore and to do so I will need to keep SDRS disabled on those VMs.  So my script needs an exceptions list, but I am not sure how to implement that.  Any help?

$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.Operation = [VMware.Vim.ArrayUpdateOperation]::edit

    $vmSpec.Info = $vm

    $vmSpec.Info.Enabled = $true

    $spec.VmConfigSpec += $vmSpec

  }

  $srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)

}

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this.

You specify the VMs to be excluded, and based on the MoRef.Value they are excluded from the ForEach loop.

$excludedVMNames = 'vm1', 'vm2', 'vm3'

$vmMorefValue = (Get-View -ViewType VirtualMachine -Property Name -Filter @{Name = "^$($excludedVMNames -join '|')$" }).MoRef.Value


$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 { $vmMorefValue -notcontains $_.Vm.Value -and -not $_.Enabled }))

   {

   $vmSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec

   $vmSpec.Operation = [VMware.Vim.ArrayUpdateOperation]::edit

   $vmSpec.Info = $vm

   $vmSpec.Info.Enabled = $true

   $spec.VmConfigSpec += $vmSpec

   }

   $srmMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef, $spec, $true)

}


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

0 Kudos