Multiple VM Storage Policies

I had an ask from a customer about how to set storage policies on multiple VMs in AVS. You can accomplish this via run commands as documented https://docs.microsoft.com/en-us/azure/azure-vmware/configure-storage-policy but the customer needed a little bit more flexibility in specifying multiple VMs to run the command against. The run command supports wild cards but that was not sufficient filtering. So of course what do we do?

Script All The THINGS!

The documentation on the az cli for AVS is a little lacking. But after some trial and error I got it to work. One of the main things I found was that the parameters are case sensitive. name != Name and the values of the parameters are case sensitive as well so vmname =! VMName. Why in the world would that be the case when other parts of the command like “–parameter” are case insensitive? Also type=Value is correct but when giving a value value="" is correct. Mixed case sensitivity is horrible. Who wrote this? Also in the examples (https://docs.microsoft.com/en-us/cli/azure/vmware/script-execution?view=azure-cli-latest) they show:

--script-cmdlet-id "/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource"

This is not correct. The correct value for --script-cmdlet-id in this instance is Microsoft.AVS.Management/3.0.51/Set-AvsVMStoragePolicy. After a good 40 minutes of hacking around the command I landed on was

az vmware script-execution create --name $execname --resource-group $resource_group --private-cloud $cloud_name --script-cmdlet-id "Microsoft.AVS.Management/3.0.51/Set-AvsVMStoragePolicy" --timeout P0Y0M0DT0H60M60S --parameter name=VMName type=Value value=$vm --parameter name=StoragePolicyName type=Value value=$storage_policy

You can find the script here: https://github.com/khensler/VMware_Scripts/blob/main/AVS/setVMStoragePolicy.ps1. It will probably throw an error but it seems to work anyways.

Time for me to submit some bugs and some documentation PRs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: