Stop and Start SSH Session – Powercli

Simple Powercli Script to stop and start ESXi SSH sessions It’s best practice to not have SSH running all the time on your ESXi hosts. The UserVars.ESXiShellInteractiveTimeOut advanced parameter should be set so SSH stops automatically after a defined amount of time. The below is a simple script which allows you to stop and start SSH sessions quickly and easily on any host, it also fires up your favorite SSH client .

$SSHhost = Read-Host 'Which Host Would you like to Start SSH on'
Get-VMHostService -VMHost $SSHhost | ?{$_.Label -eq "SSH"} | Start-VMHostService

###Opens up your favourite SSH Client###
C:\Program Files (x86)\Putty\Putty.exe

###Stop SSH###
Write-Host "Click enter to Stop the SSH Service" -ForegroundColor Green
pause
Get-VMHostService -VMHost $SSHhost | ?{$_.Label -eq "SSH"} | Stop-VMHostService -Confirm:$false