Changing the vSAN Storage Policy for a VM using PowerCLI

Posted by Stephan McTighe on 11 Sep 2023

I recently had a query regarding changing the storage policy on a significant number of virtual machines using PowerCLI.

Here is a quick script that can be leveraged to do this:

In the foreach loop you will need to define the scope of objects you want to make the change to, as well as the name of an existing storage policy you wish to apply, for the StoragePolicy parameter.

1forEach($_ in (get-vm <scope>)){
2
3Set-SpbmEntityConfiguration -Configuration (Get-SpbmEntityConfiguration $_) -StoragePolicy "lab-raid-5"
4Set-SpbmEntityConfiguration -Configuration (Get-SpbmEntityConfiguration (get-vm $_ | Get-HardDisk)) -StoragePolicy "lab-raid-5"
5
6}

In the UI, you will see there is the option to change the policy for all the VM’s objects or on a per object or disk basis. This is the same when done via PowerCLI.

The main difference is that you need to target both the VM and the HardDisks, hence the two Set-SpbmEntityConfiguration lines in the code. The first targets the VM object(s), while the second targets the disks.

Just the VM:

VM and Disks:

Hope this has been helpful and make sure you test appropriately!

As always, thanks for reading!

If you like my content, consider following me on Twitter so you don’t miss out!