As per http://communities.vmware.com/message/2172311#2172311
I'm using LucD's method, to extract a list of vm's that have vm's turned on
This successfully gets a list of vm's that have sdrs enabled that shouldnt.
I'm struggling with how to disable sdrs. I'm new to powershell
from what i can gather i need to update dsc.podstoragedrsentry.storagedrsconfig.vmconfig.enabled to False.
but i'm unsure how to do this, or could point me in the right direction?
You will have to use the ConfigureStorageDrsForPod_Task method to change the settings for SDRS.
In the StorageDrsConfigSpec object you can disable this.
Combined with your Where-clause this could be something like this
$storMgr = Get-View StorageResourceManager
$pod = Get-DatastoreCluster -Name $datastorecluster
$spec = New-Object VMware.Vim.StorageDrsConfigSpec $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {(Get-View $_.VM | Select -ExpandProperty Name) -like "*_replica"} | %{ $entry = New-Object VMware.Vim.StorageDrsVmConfigSpec
$entry.Operation = "edit"
$entry.Info = $_
$entry.Info.Enabled = $false
$spec.vmConfigSpec += $entry
} $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)
Note that the Get-DatastoreCluster cmdlet can be used to replace my function
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You will have to use the ConfigureStorageDrsForPod_Task method to change the settings for SDRS.
In the StorageDrsConfigSpec object you can disable this.
Combined with your Where-clause this could be something like this
$storMgr = Get-View StorageResourceManager
$pod = Get-DatastoreCluster -Name $datastorecluster
$spec = New-Object VMware.Vim.StorageDrsConfigSpec $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {(Get-View $_.VM | Select -ExpandProperty Name) -like "*_replica"} | %{ $entry = New-Object VMware.Vim.StorageDrsVmConfigSpec
$entry.Operation = "edit"
$entry.Info = $_
$entry.Info.Enabled = $false
$spec.vmConfigSpec += $entry
} $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)
Note that the Get-DatastoreCluster cmdlet can be used to replace my function
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Cheers Mate!
That's just what i needed, need to learn a bit more powershell to fully follow how to replicate how you did this but thanks :^)
As a matter of fact this is PowerShell/PowerCLI using one the SDK API to change the settings.
Not all vSphere API are available through PowerCLI cmdlets, but it is quite easy to call the SDK API directly from within PowerCLI/PowerShell.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script seemed to be working as expected, but recently I noticed that New VM's that are added to the datastore cluster won't appear when you run $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig
I haven't been able to get them detected and working, Does anyone know if there is anything that needs to be done after adding a vm to have it appear from powercli when looking at members of a SDRS cluster?
I suspect that the new information is not present.
Remember that the objects you get in PowerCLI are read-only copies.
You can force a refresh with
$pod.ExtensionData.UpdateViewData()
Does that help ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the quick response LucD
No luck,
Ran $pod.ExtensionData.UpdateViewData() then $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig
the new VM won't show in powercli, however shows fine in GUI
Any idea on how often it refreshes?
The PowerCLI object does not refresh, unless you do an UpdateViewData.
Did you try fetching the datastorecluster object again
$pod = Get-DatastoreCluster -Name $datastorecluster
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm having the same problem where newly added VMs to the datastore cluster failed to show up in ~StorageDrsConfig.VmConfig. One way I've found to get them to show up is to enable/disable storage DRS from vSphere Client on the datastore cluster. For some reason, after doing that from the vSphere GUI, the VMs show up then in ~StorageDrsConfig.VmConfig. I tried using Set-DatastoreCluster to change the sdrsautomationlevel to manual / disabled, but no luck in getting the VMs to show up. So far, only after editing the datastore cluster settings from vSphere client. Not sure if it might be an issue with the vCenter Server not passing the information along or what. I'd be curious to know what versions you're using. I'm using ESXi 5.1U1, vCenter Server 5.1U1, and PowerCLI 5.1 release 1.
The changes you make in vCenter are not automatically done in your PowerCLI variables.
You will have to get the object again, or refresh the ExtensionData property with the UpdateViewData method.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, forgot to mention that I re-fetched the datastore cluster object after adding VMs to it, and also after changing the sdrsautomationlevel with Set-DatastoreCluster. Unfortunately, it still had nothing in ~.StorageDrsConfig.VmConfig. Only after making the changes in vCenter and getting the object again after making the changes did the VMs finally show up in ~.StorageDrsConfig.VmConfig.
The ExtensionData property is handled a bit differently, compared to regular PowerShell variables and their properties.
Did you also try with the UpdateViewData method as I suggested ?
It might be a caching problem.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yeah, I tried that too to no avail
I'll check if I can reproduce that
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I tried $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig
then
$pod.ExtensionData.UpdateViewData()
then
$pod = Get-DatastoreCluster -Name $datastorecluster
The VM still doesnt appear when I do a $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig
VM was added more than a week ago, so it doesnt seem to be an internal refresh timer.
I did some more tests, and I can confirm the behavior you are seeing.
When a new VM is created on the datastorecluster it is not automatically added to the VmConfig array as a StorageDrsVmConfigInfo entry.
The fact that you see it in the vSphere client is due to the defaults (see for example the description of the enabled property).
I'm not sure if this is intentional or a "feature".
My guess is that this is intentional, as long as you don't divert from the defaults, there is no need to create an entry.
Perhaps some SDRS wizard can shine his light on this ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just checking tho, there is no way to update this from the VM side?
Hi!
I am getting below errors while running this script, though sometimes it do the changes in VM SDRS automation but throwing this error.
Exception calling "ConfigureStorageDrsForPod" with "3" argument(s): "The object has already been deleted or has not been completely created"
At line:1 char:1
+ $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Hi rajan. I am getting the same errors occasionally though, as you say, sometimes the rule gets correctly created. Have you found any workaround or root cause?
Hi,
Sorry to update this thread, but I need to put all my automation level to 'default'.
When VM are in Default mode, seems that everything is empty, example:
Vm | : VirtualMachine-vm-13297 |
Enabled | : |
Behavior | : |
IntraVmAffinity | : |
IntraVmAntiAffinity :
LinkedView | : |
DynamicType | : |
DynamicProperty | : |
So I Try to do the same thing with a StorageDrsVmConfigSpec:
$storMgr = Get-View StorageResourceManager
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$dsc = Get-Datastorecluster DS1
$dsc.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig |%{
$entry = New-Object VMware.Vim.StorageDrsVmConfigSpec
$entry.Operation = "edit"
$entry.Info = $_
$entry.Info.Enabled = ""
$entry.Info.Behavior = ""
$entry.Info.IntraVMAffinity = ""
$spec.vmConfigSpec += $entry
}
$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
But ... no luck:
Exception calling "ConfigureStorageDrsForPod" with "3" argument(s): "A specified parameter was not correct.
spec"
Any idea ? 🙂