PowerCli – Ensure idle ESXi shell and SSH sessions time out after 300 seconds or less

In this blog, we will ensure an inactivity timeout is applied to our esx host.

Get-vmhost | Get-AdvancedSetting UserVars.ESXiShellInteractiveTimeOut

#####################################################################
# Ensure idle ESXi shell and SSH sessions time out after 300 seconds or less  #
# Tested by Ash on 28 Oct
# V1.0
######################################################################
  
#Variables
$vCenter = "sfo-m01-vc02.ash.local"
$Cluster = "vSAN-Production"
  
### Start of Script
# Load VMware Cmdlet and connect to vCenter
Add-PSSnapin vmware.vimautomation.core
connect-viserver -server $vCenter
  
$VMHost = Get-Cluster -Name $Cluster | Get-VMhost
  
# List UserVars.ESXiShellInteractiveTimeOut for each host
ForEach ($VMhost in $Cluster){
Get-VMHost | Select Name, @{N="UserVars.ESXiShellInteractiveTimeOut";E={$_ | Get-AdvancedSetting UserVars.ESXiShellInteractiveTimeOut | Select -ExpandProperty Values}}
}

# pausing for user input
pause 

# Set Remove UserVars.ESXiShellInteractiveTimeOut to 300 on all hosts
ForEach ($VMhost in $Cluster){
Write-Host -ForegroundColor GREEN "Setting ESXiShellInteractiveTimeOut Policy on " -NoNewline
Write-Host -ForegroundColor YELLOW "$VMhost"
Get-VMHost | Get-AdvancedSetting -Name 'UserVars.ESXiShellInteractiveTimeOut' | Set-AdvancedSetting -Value "300"
} 
 
### End of Script


(Visited 469 times, 1 visits today)

By C A Thomas

Chinchu A. Thomas is an Infrastructure Analyst specializing in Microsoft Azure, the Microsoft 365 suite, AWS, and Windows infrastructure management products.

Leave a Reply