PowerCLI – Orchestrating bulk advanced setting modifications on a VM

I was recently looking to make an change to the advanced settings of a number of virtual machine to which this required the virtual machine to be powered down in order to apply.

Firstly, we will establish a connection to the vCenter system.

If (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) 
    Add-PSSnapin VMware.VimAutomation.Core | Out-Null 

Connect-VIServer server1.domain.local | Out-Null

Now, we build a collection of virtual machines to invoke the script block, in this example I will be retrieving all virtual machines in a cluster named ‘Cluster1’ .

$VMs = Get-Cluster "Cluster1" | Get-VM

For each virtual machine retrieved in the collection we will perform an operation to orchestrate the a shutdown operation to the guest operating system, wait until the powerstate is returned as ‘PoweredOff’ , apply the advanced setting and finally power on the virtual machine.

In this example, we will be modifying the advanced setting ‘isolation.tools.autoInstall.disable’ to a value of ‘False’, where the Force parameter is used to overwrite the current setting and Confirm parameter is configured not to require user interaction.

ForEach ($VM in $VMs) 
        Shutdown-VMGuest -VM $VM.Name -Confirm:$false 
            Start-Sleep -Seconds 5
        Until ((Get-VM $VM.Name).PowerState -eq "PoweredOff") 
        Get-VM $VM.Name | New-AdvancedSetting -Name "isolation.tools.autoInstall.disable" -value "$false" -Force -Confirm:$false 
        Start-VM -VM $VM.Name -Confirm:$false 

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