SDRS VM settings always set to fullyautomated with New-VM cmdlet

New-VM cmdlet

Came across an issue when doing deployment of VMs using the PowerCli cmdlet New-VM. If not specified and deployed into a datastore cluster, SDRS behavior will always be set to automated. Even if the datastore clusters default setting is set to something else. It seems weird to bypass the datastore clusters default settings and per default just set it to automated, but that is just how it is at the moment. Consider this to be a request to change default behaviour of the cmdlet, to always set the SDRS setting of the VM to default unless otherwise specified.

This is an example of a command to be used for creating a new VM in a given Datastore Cluster

New-VM -Name “VM01” -Datastore “DSC01”

As seen in the screenshot. One of the VMs is listed with a Storage DRS Automation Level of Fully Automated, instead of Default. Which is what a VM would use by default if created via a GUI.


There is a simple fix for this when creating a new VM, using the New-VM cmdlet. Simply add the option -DrsAutomationLevel with value set to AsSpecifiedByCluster. This will make sure the VM is getting the default setting of the datastore cluster, when ever that might be. So why should you care if you already are setting the datastore cluster to fully automated? The simple answer is that might change and if you do not have all your VMs set to use the default setting of the cluster, it would mean you had to change settings on each individual VM. I is just so much easier to have all VMs using default as behaviour, cause then you would only need to change the datastore cluster settings and not the setting of each individual VM.


New-VM -Name “VM01” -Datastore “DSC01” -DrsAutomationLevel AsSpecifiedByCluster


How to change behaviour

Well if you already have this problem, you could manually change all VMs to the default setting again. But that would be no fun. Lets fix the problem with some more PowerCli code. I’m a true believer in a good admin is a lazy admin! So the code below I did not create my self! I had an awesome little fling create it for me. Cue the fanfare and give it up for Onxy. If you do not know Onxy, it is a tool which can put out code of actions done in either the fat c# client or now a days in the webclient, both flings can de found here. When I say put out code, what I mean is that it sits in between your client and the vCenter server and intercepts all the API calls. In Onxy for the fat client, you can even choose what scripting language you want the code out in. I obviously selected PowerCli. The thing is that is is raw code used for that specific task you did in the vCenter client. So modifications are almost always needed to be used otherwise. Some changes has also been done to this script.  I define a datastore cluster to run this on and have a where statement which means it will only alter VM settings if the Storage DRS Automation Level contains the work automated. This reason for this is that you might have done other changes which you do not want to be reversed. One could argue that checking the datastore clusters current level of automation first, before making changes, could make the script even better and suited for more use cases. I did not have that need so it is what it is. If you for some reason need to bulk change another setting a will. Simply change the matched behaviour to fit your needs.


The script


Hope this saves you some trouble and some time.

Leave a Reply

Your email address will not be published. Required fields are marked *