Updating ESXi host advanced settings using PowerCLI

Hi all,

I needed to update my lab recently so that I was using the host advanced settings that my performance and support guys recommended for my specific storage (DataGravity of course!)  The settings are:

Net.TcpipHeapSize=32

Net.TcpipHeapMax=128

NFS.MaxVolumes=256

NFS.MaxQueueDepth=32

I wanted to do this in a mostly automated and safe way.  I checked the Internet and found things that were close to what I needed but not quite.  So after a while of working, and a bunch of testing I had two scripts.  The first would connect to your vCenter and check what the settings above were set too on each host and create a CSV file from that.  So a report and a backup!  The second script would make the change.

See way below for the scripts.

I did notice something interesting when I checked my file.  The MaxQueueDepth was 4294967295.  So a pretty odd queue depth I think – update – Thanks to MikeL I learned that this number means unlimited.  I checked in both of my labs and found them both like that for all hosts.

I hope that this helps you out as these settings are important.  And yes, these scripts will work well if you change them to suit you in doing other values or even other parameters.

dgset.csv

Below you can see a screenshot of the dgset.csv after we have made the changes, and in fact after we have restarted the servers.

The dgset.csv file seen in Excel

The dgset.csv file seen in Excel

 Scripts

Both scripts were done using PowerCLI 5.8 and PowerShell 3.0.  They were both tested carefully and work well.  However, both will display a red error that will not hurt operation when they are run the very first thing in a PowerCLI session.  I am trying to figure that out and will update the scripts when I do.  If they are run twice, or if they are run second after a different script that talks to vCenter they will not show a red error.

While the DGSetSettings script will set the parameters, and you can see that with the DGShowSettings script, the changes will not be active until the hosts are restarted.  Thanks goodness for Maintenance Mode!

You can successfully copy and paste the scripts below into your favorite editing tool.  I use Sublime (Mac) and Notepad++ (Windows).

DGShowSettings.ps1

This will will create a file in C:\scripts called dgset.csv.  It will have the four variables seen above, their values, and it will be done for every host in your vC inventory.  Use the CSV for backup but also for checking.

</pre>
# =============================================================================================

# This script will show the Advanced settings that are important to DataGravity arrays.

# AUTHOR        Michael White - http://notesfrommwhite.Net
# Update        2/18/15 - Brian Graf
# Output    The output file is c:\scripts\DGSet.csv - it can be changed below.
# Purpose     To ask for vC info, connect to vC, and for each ESXi host retrieve certain NFS / NET info and put in CSV.
# =============================================================================================

Clear-Host

if ( (Get-PSSnapin -Name 'VMware.VimAutomation.Core' -ErrorAction SilentlyContinue) -eq $null )
{
    Add-Pssnapin 'VMware.VimAutomation.Core' -ErrorAction SilentlyContinue
}

#===============================================================================================
Write-Host "Producing a CSV with certain NFS and NET info from each host`r`n"
do {
$servername = Read-Host 'What is your vC name (FQDN)?'
}until ($servername -ne $null -and $servername -ne "")

Write-Host
# =============================================================================================

# ------ Test server name passed ------
if($global:DefaultVIServer){
Write-Host "vCenter Connection found. Disconnecting to continue..."
Disconnect-ViServer -Server * -Confirm:$False -Force
}

 Write-Host "Connecting to [$servername]" -ForegroundColor Yellow
 $connection = connect-viserver $servername
 if($connection.isconnected -eq "true"){Write-Host "Connected!" -ForegroundColor Green}else{Write-Host "Something Went Wrong..." -ForegroundColor Red}
 Write-Host "StandBy .. gathering data!" -ForegroundColor Yellow

#--- Get all hosts and keep only the name
$esxHosts = Get-VMHost | Where { $_.PowerState -eq "PoweredOn" -and $_.ConnectionState -eq "Connected" } | Sort Name
if (!(Test-Path "c:\Scripts")) { New-Item -ItemType directory -Force -Path "c:\Scripts"}

foreach($esx in $esxHosts){

    #Write-Host "Displaying TCP and NFS Advanced Configuration Settings on $esx"
    Get-AdvancedSetting -Entity $esx -Name Net.TcpipHeapSize | Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\dgset.csv

    Get-AdvancedSetting -Entity $esx -Name Net.TcpipHeapMax | Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\dgset.csv

    Get-AdvancedSetting -Entity $esx -Name NFS.MaxVolumes | Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\dgset.csv

    Get-AdvancedSetting -Entity $esx -Name NFS.MaxQueueDepth | Select Entity,Name,Value | Export-CSV -NoTypeInformation -Append -path c:\scripts\dgset.csv
      
   }

   Write-Host

   Write-Host "Done.  Check the c:\scripts\dgset.csv file now." -ForegroundColor Green

   Write-Host "Be aware that each run of this script will append to that file."

DGSetSettings.ps1

This script will make the changes that are talked about above.


=============================================================================================

# This script will set the appropriate Advanced settings that are important to DataGravity arrays.
# AUTHOR        Michael White - http://notesfrommwhite.net  
# Update        2/18/15 Brian Graf
#
# Output     
# Purpose     Adv ESXi Settings changed for each host in your cluster
# =============================================================================================
Clear-Host

if ( (Get-PSSnapin -Name 'VMware.VimAutomation.Core' -ErrorAction SilentlyContinue) -eq $null )
{
    Add-Pssnapin 'VMware.VimAutomation.Core' -ErrorAction SilentlyContinue
}

#===============================================================================================

Write-Host "Setting various Advanced settings as per this script!" -ForegroundColor Yellow

write-Host

Write-Host "Did you run the DGShowSettings.ps1? - it is your backup" -ForegroundColor Yellow

Write-Host "If you haven't, <ctrl + C> and do it now!" -ForegroundColor Yellow 

Write-Host

do {
$servername = Read-Host 'What is your vC name (FQDN)?'
}until ($servername -ne $null -and $servername -ne "")

Write-Host
# =============================================================================================

# ------ Test server name passed ------
if($global:DefaultVIServer){
Write-Host "vCenter Connection found. Disconnecting to continue..."
Disconnect-ViServer -Server * -Confirm:$False -Force
}

 Write-Host "Connecting to [$servername]" -ForegroundColor Yellow
 $connection = connect-viserver $servername
 if($connection.isconnected -eq "true"){Write-Host "Connected!" -ForegroundColor Green}else{Write-Host "Something Went Wrong..." -ForegroundColor Red}

write-Host
write-Host "StandBy .. doing stuff!" -ForegroundColor Yellow

$esxHosts = Get-VMHost | Where { $_.PowerState -eq "PoweredOn" -and $_.ConnectionState -eq "Connected" } | Sort Name

foreach($esx in $esxHosts) {

    Write-Host "Updating TCP and NFS Advanced Configuration Settings on $esx"

    # Update TCP Settings

    Get-AdvancedSetting -Entity $esx -Name Net.TcpipHeapSize | Set-AdvancedSetting -Value '32' -Confirm:$false

    Get-AdvancedSetting -Entity $esx -Name Net.TcpipHeapMax | Set-AdvancedSetting -Value '128' -Confirm:$false

    # Update NFS Settings

    Get-AdvancedSetting -Entity $esx -Name NFS.MaxQueueDepth | Set-AdvancedSetting -Value '32' -Confirm:$false

    Get-AdvancedSetting -Entity $esx -Name NFS.MaxVolumes | Set-AdvancedSetting -Value '256' -Confirm:$false

}

Write-Host

Write-Host "Done" -ForegroundColor Green

Thanks for reading and checking this out – let me know if you have questions or comments.  Or, if you have suggestions on improving my scripting that would be good too!

Update:

  • 1/8/16 – For vSphere 6, the heap max can be 1536.  Rest of numbers here are good.
  • 9/28/15 – Above I use 256 as the max number of volumes.   That is the max value and is tested, but I suggest you use 32 as a more realistic number.  Thanks to Daniel for reminding me of this.
  • 2/26/15 – Thanks to Mike Long I learned that the odd number is in fact signifying unlimited.  I updated that above.
  • 2/20/15 – Thanks to Brian Graf I have a new version of these scripts.  They still appear to work the same, and do the same thing.  But if you look at the code you can see they are much better.  I told Brian that it was the difference between a guy that can copy and paste and make something work, and a professional.  So wonderful examples of how a pro would do things!

Michael

=== END ===

Tagged with: ,
Posted in How To

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: