Working with ESXi Advanced Settings

Well there was a situation where a customer was experiencing performance issues and upon a lot of troubleshooting, there was a need to modify few of the ESXi advanced settings (Caution: Please consult VMware GSS before modifying any of the ESXi advanced settings as changing them may have an impact on other settings as well).

Customer wants their infra and all other settings to be identical on all ESXi hosts (of course which is a best practice too). Considering the large size of the infra, changing multiple settings on so many number of hosts is going to take a significant amount of time. So, I thought of writing a script that can check the ESXi current setting and modify if the value doesn’t match the desired value.

#Author: Mallikarjun Immadi
#Website: https://www.vpxd.in

##########################################
#Defining Functions
##########################################

function Get-AdvancedSystemSetting{
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.VIObjectImpl]$cluster,
[Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()]
[String[]]$advSetting
)
Get-Cluster $cluster | Get-VMHost | Where {$_.ConnectionState -notlike "notresponding"}| Get-AdvancedSetting -Name $advSetting| Select-Object entity,name,value | Format-Table -AutoSize
}

function Set-AdvancedSystemSetting{
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.VIObjectImpl]$cluster,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()] [String[]]$advSetting,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$advValue
)
$esxHosts= Get-Cluster $cluster | Get-VMHost | Where {$_.ConnectionState -notlike "notresponding"}
Write-Host "Applying Configuration Changes" -ForegroundColor Yellow
foreach ($esx in $esxHosts) { Get-AdvancedSetting -Entity $esx -Name $advSetting | where {$_.Value -notlike $advValue} |Set-AdvancedSetting -Value $advValue -Confirm:$false }
Write-Host Write-Host "Values after configuration changes" -ForegroundColor Green Get-Cluster $cluster | Get-AdvancedSystemSetting -advSetting $advSetting
}

###############################################
#Working with the defined functions
###############################################

#Defining Variables
$cluster = 'Standalone-Cluster'
$advSetting = 'Vpx.Vpxa.config.workingDir'
$advValue = '/var/log/vmware/vpx'

#Connecting to vCenter Server
$vCenterServer = Read-Host "Enter vCenter Server FQDN or IP Address"
Connect-VIServer $vCenterServer
#Get the current configured values
Get-Cluster $cluster | Get-AdvancedSystemSetting -advSetting $advSetting

#Change the values to desired ones if configured values doesn't match with desired ones (Set-AdvancedSystemSetting function will compare the configured value with the desired one).
Get-Cluster $cluster | Set-AdvancedSystemSetting -advSetting $advSetting -advValue $advValue

Script needs below input parameters.

  1. Cluster Name (Customer wants perform activity cluster by cluster to avoid surprises and wants to implement the changes cluster by cluster)
  2. ESXi Advanced Setting Key name
  3. ESXi Advanced Setting Key value

Get-AdvancedSystemSetting function can be called display the current setting values where as Set-AdvancedSystemSetting function can be called to set the values.

Set-AdvancedSystemSetting function will check the current value and modifies only if doesn’t match with the desired value. If key value matches, then it won’t modify anything.

Script can be downloaded from here.

NOTE: PLEASE CONSULT VMWARE GSS BEFORE MAKING ANY CHANGES TO THE ESXI ADVANCED SETTINGS.