Using PowerShell to change ESXi Advanced Settings

I'm always needing to change ESXi advanced settings - typically against a large number of hosts.

I'm also always forgetting the PowerShell syntax to get, then set the advanced setting, so here is a code snippet.

Remember that you need to firstly get the current value of the setting using Get-AdvancedSetting then pipe it to Set-AdvancedSetting in order to set it.

Here's an example to configure Net.ReversePathFwdCheckPromisc with a value of 1 across all hosts in a vCenter server.

connect-viserver vc01.kfmlab.local

$esxHosts = Get-VMhost

foreach ($host in $esxHosts) {

    # Call Get-AdvancedSetting then pipe to Set-AdvancedSetting
    Get-AdvancedSetting -Entity $host -Name "Net.ReversePathFwdCheckPromisc" | Set-AdvancedSetting -Value 1 -confirm:$false


disconnect-viserver vc01.kfmlab.local