Start and Stop ESXi hosts SSH Service with Powershell

There are lot of times when troubleshooting a certain issue in VMware environment, you need to enable SSH service on some hosts. Enabling the SSH service is a bit a time-consuming process when it comes to several hosts at a time.

Thanks to PowerCLI which makes VMware admins’ life a lot easier. The following is a simple script starting or stopping SSH service of ESXi hosts.

The reason I am using a variable to identify SSH Service is that, the cmdlet does not accept any parameters with the name of the service or its label. Now lets see each command in practice.

$All_Hosts = Get-VMHost, it returns all hosts within vCenter, in this case, I want all hosts’ SSH service to be running.

$SSH_Service = get-VMHostService -VMHost $All_Hosts | where {$_.Label -eq “SSH”}, this returns all hosts’ SSH service. As you see there are several hosts here which their SSH service is currently stopped.

SSH Service

Start-VMHostService -HostService $SSH_Service, it starts all the hosts SSH service. if you re-check the status, they all have changed to True.

Leave a Reply

Your email address will not be published.