PowerCLI: Copying Advanced Host Configuration

I was asked in my script list comments if there was a way to copy the ESX host advanced configuration from one host to every other host in the cluster, thankfully PowerCLI gives us some nice cmdlets to work with that make this task very easy…

Get-VMHostAdvancedConfiguration and Set-VMHostAdvancedConfiguration

So first of all lets list the current advanced configuration of one of our hosts using Out-GridView:

Get-VMHost "vmgesx4-01.vmguru.com" | Get-VMHostAdvancedConfiguration | Out-GridView

image

So, all we need to do is setup a gold build host with the configuration we need, we can then take these settings and apply them to every other host in our cluster with a few lines.

Lets first store our gold build host in a variable…

$GoldHost = "esx1.mydomain.com"

Then we can store the name of our cluster in a variable…

$Cluster = "Non-Production"

Now we can get the advanced configuration settings for the gold build host and store these ready for applying to all other hosts in our cluster…

$GoldConfig = Get-VMHost $GoldHost |Get-VMHostAdvancedConfiguration

A simple foreach loop will then get the hosts in our named cluster, ensuring we don’t get the host which we are using as the gold build, no point in applying the settings over the top 😉

Foreach ($ESXHost in (Get-Cluster $Cluster | Get-VMHost | Where {$_.name-ne $GoldHost})){
 Write-Host -ForegroundColor Yellow "Setting advanced config for $ESXHost"
 Get-VMHost $ESXHost | Set-VMHostAdvancedConfiguration $GoldConfig -WhatIf
}

As it stands the script will currently tell you what it will change for each host without making any changes at all, this is down to the -WhatIf parameter in the loop, simply remove this to make the script apply the settings.

Hey presto, we now have all our advanced settings replicated to each host in the cluster, we can be safe that we have not missed a cluster or made a spelling mistake or added a wrong value accidently.

The script in full:

$GoldHost = "esx1.mydomain.com"
$Cluster = "Non-Production"

$GoldConfig = Get-VMHost $GoldHost |Get-VMHostAdvancedConfiguration

Foreach ($ESXHost in (Get-Cluster $Cluster |Get-VMHost |Where {$_.name-ne $GoldHost})){
    Write-Host -ForegroundColor Yellow "Setting advanced config for $ESXHost"
    Get-VMHost $ESXHost |Set-VMHostAdvancedConfiguration $GoldConfig -WhatIf
}

Example Output:
Setting advanced config for esx1.mydomain.com

What if: Modify ‘VMkernel.Boot.tty2Term’ option?

What if: Modify ‘Net.TcpipDefLROEnabled’ option?

What if: Modify ‘Misc.EnableHighDMA’ option?

What if: Modify ‘VMkernel.Boot.assumePerNodeBusClock’ option?

What if: Modify ‘Misc.BlueScreenTimeout’ option?

What if: Modify ‘Config.Defaults.cpuidMask.val.1.edx’ option?

What if: Modify ‘Net.MinEtherLen’ option?

What if: Modify ‘Net.VmklnxLROMaxAggr’ option?

What if: Modify ‘NFS.IndirectSend’ option?

What if: Modify ‘Numa.PostMigUseActiveMetric’ option?

What if: Modify ‘FT.HeartbeatCount’ option?

What if: Modify ‘Net.GuestTxCopyBreak’ option?

What if: Modify ‘Net.configOption[CONFIG_NET_INPUT_FLUSH_MAX_PKTS]’ option?

What if: Modify ‘Disk.RetryUnitAttention’ option?

What if: Modify ‘Scsi.TimeoutTMThreadMax’ option?

What if: Modify ‘Net.CoalesceFavorNoVmmVmkTx’ option?

What if: Modify ‘Disk.QFullThreshold’ option?

What if: Modify ‘Net.CoalesceHandlerPcpu’ option?

What if: Modify ‘Mem.SampleActivePctMin’ option?

What if: Modify ‘Disk.ThroughputCap’ option?

etc etc…..

3 thoughts on “PowerCLI: Copying Advanced Host Configuration

  1. Michael Poore

    Alan,

    Shouldn’t the final line of the code be:

    Get-VMHost $ESXHost | Set-VMHostAdvancedConfiguration $GoldConfig -WhatIf

    Great script though, thank you.

  2. Pingback: uberVU - social comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.