Enable/Disable SSH on all ESXi hosts

Sometime you may see a need to enable or disable SSH on all hosts in a cluster. This post will help you achieve that quickly using the PowerCLI.

Connect to vCenter Server using PowerCLI and use the below command to check the status of the SSH and ESXi Shell on hosts.

SSH Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } |select VMHost, Label, Running
 ESXi Shell Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM" } |select VMHost, Label, Running

1

 

We see the both the services are not running, to start them use the below commands.

SSH Get-VMHost | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
 ESXi Shell Get-VMHost | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM"} )}

2

You should now see the services running. To run these againt a cluster, use Get-Cluster cmdlet.

Get-Cluster -Name “ClusterA” | Get-VMHost | Get-VMHostService | Where { $_.Key -eq "TSM-SSH" } |select VMHost, Label, Running

Hope this was informative. Thanks!

Advertisements