Hi,
for VMs with storage/vDisks >1 TB we override the "Keep VMDKs together" policy with "No". This is usually done while deployment or expansion of a VM. For whatever reason these overrides get lost sometimes (there is KB about this http://kb.vmware.com/kb/2053792Storage DRS keeps VMDKs together and does not allocate to most optimal datastore , but AFAICS nobody here uses the C# client for theses settings any more).
I'm tired of setting theses overrides ever week again. So I want to create a powercli script that checks for VMs with > 1TB vDISKs (diskspace used for all vDisks) and create a VM override rule. I did not find anything how to set this with powercli, anyone has an idea or a quick example?
Thx!
Something like this then ?
$dscName = 'MyDSC'
$maxGB = 1024
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$dsc = Get-DatastoreCluster -Name $dscName
$dsc | Get-VM |
Where {(Get-HardDisk -VM $_ | select -ExpandProperty CapacityGB | Measure-Object -Sum | Select -ExpandProperty Sum) -ge $maxGB} | %{
$vm = New-Object VMware.Vim.StorageDrsVmConfigSpec
$vm.Operation = 'edit'
$vm.Info = New-Object VMware.Vim.StorageDrsVmConfigInfo
$vm.Info.vm = $_.ExtensionData.MoRef
$vm.Info.Enabled = $true
$vm.Info.intraVmAffinity = $false
$vm.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated
$spec.VmConfigSpec += $vm
}
$si = Get-View ServiceInstance -Server $global:DefaultVIServer
$storMgr = Get-View -id $si.Content.StorageResourceManager -Server $global:DefaultVIServer
$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can do something like this
$dscName = 'MyDSC'
$maxGB = 1024
Get-DatastoreCluster -Name $dscName | Get-VM |
Where {(Get-HardDisk -VM $_ | select -ExpandProperty CapacityGB | Measure-Object -Maximum | Select -ExpandProperty Maximum) -ge $maxGB} |
Set-SdrsAntiAffinity -DatastoreCluster $dscName
It uses the function from my Automate your SDRS Anti-Affinity rules post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the suggestion. It looks like the script is looking for individual disk sizes (1024) where I want to lookup the complete disk capacity of a VM. We have large SQL VMs with 6-10 vDISKs where each one might be smaller than 1 TB but all together they are > 1 TB (or even bigger than the max size of our datastores).
This seems to work: Get-DatastoreCluster -Name $dscName | get-vm | Where {$_.ProvisionedSpaceGB -ge $maxGB}
I'll have a look it again tomorrow morning, thx!
In that case change the Where-clause to summation
$dscName = 'MyDSC'
$maxGB = 1024
Get-DatastoreCluster -Name $dscName | Get-VM |
Where {(Get-HardDisk -VM $_ | select -ExpandProperty CapacityGB | Measure-Object -Sum | Select -ExpandProperty Sum) -ge $maxGB}
Set-SdrsAntiAffinity -DatastoreCluster $dscName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I see a difference when I use Set-SdrsAntiAffinity to add and override in Web Client. In Web Client I got to the sDRS cluster -> Settings -> Configuration -> VM Overrides, add a VM and set "Keep VMDKs together" to "No". With this I only get an override for "keep together". Set-SdrsAntiAffinity does this too but also adds a VMDK anti affinity rule. This is not necessary what I want, it would be fine if the majority of a VM's vDisks would be on the same datastore but sDRS can svMotion one disk if needed to another DS. Is there a way to only set the override for "keep together" without anti-afinity rule for the vDisks?
Something like this then ?
$dscName = 'MyDSC'
$maxGB = 1024
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$dsc = Get-DatastoreCluster -Name $dscName
$dsc | Get-VM |
Where {(Get-HardDisk -VM $_ | select -ExpandProperty CapacityGB | Measure-Object -Sum | Select -ExpandProperty Sum) -ge $maxGB} | %{
$vm = New-Object VMware.Vim.StorageDrsVmConfigSpec
$vm.Operation = 'edit'
$vm.Info = New-Object VMware.Vim.StorageDrsVmConfigInfo
$vm.Info.vm = $_.ExtensionData.MoRef
$vm.Info.Enabled = $true
$vm.Info.intraVmAffinity = $false
$vm.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated
$spec.VmConfigSpec += $vm
}
$si = Get-View ServiceInstance -Server $global:DefaultVIServer
$storMgr = Get-View -id $si.Content.StorageResourceManager -Server $global:DefaultVIServer
$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank LucD, this works. I'm still a bit curious which of the lines in the scrip is the "keep together" part and how I could check this setting?
If you set $vm.Info.intraVmAffinity to $true, the VMDK will stay together
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thx LucD, I can work with that.
Hi,
is there a way to set the behaviour to the cluster default value?
$vm.Info.Behavior =[VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated
I see only manual and automated as values?
If you do not create an entry under vmConfigSpec for that specific VM, the VM will get the Storage Cluster defaults
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Maybe I was not completely clear. I still want to override the "keep together" rule, but want to keep the Default automation level.
I think I can simply remove the "$vm.Info.Behavior = [VMware.Vim.StorageDrsPodConfigInfoBehavior]::automated" line but it would be nice if I could change the "automated" to "default".
I suspect if you don't set the property, you will get "Default" by default.
Or do you see another result ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
As far as I can see it simply keeps the value if I remove the line. So if it's set to automated and I only set the affinity rule for the VMDK's it will keep this setting. I'd like to do both in my script, set the anti affinity rule for disks (remove keep together rule) and set the policy to default.
I suspect it is related to the Enabled property.
If it is not enabled, for the VM, it will get the DSC default, but that would mean you get also the default VMDK setting
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
I'm new here with vmware scripting.
I declared manually the VMs to no keeping the VMDKs together in datastore cluster setting > virtual machine settings.
And I'm trying to get a view with PowerCLI to see which VM are keeping VMDK together.
Do you have any tips or cmdlets to recommend to use please ?
Thanks.
There are currently no PowerCLI cmdlets to query SDRS, so you'll have to go into the ExtensionData property.
Something like this for example
$dscName = 'MyDSC'
$dsc = Get-DatastoreCluster -Name $dscName
$dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | Select @{N='Pod Name';E={$dsc.Name}},
@{N='POD VMDK Affinity';E={$dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.PodConfig.DefaultIntraVmAffinity}},
@{N='VM';E={Get-View -Id $_.VM -property Name | Select -ExpandProperty Name}},
@{N='VM VMDK Affinity';E={$_.IntraVmAffinity}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great! It's working you rock !
Do you have any doc url to get this information ?
I got visdk25programmingguide pdf file for cmdlets but that's all 😕
Thank you for your help
I found the API reference index !
Thanks again.
There is also a Programmer's Guide in that library.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference