Search
  • khushnood khan

Start Stop SSH for esxi hosts through power cli.

One of the big challenge for VMware admins is to make sure all the esxi hosts should not have ssh enabled at the end of the work. The challenge is more when you have a very large environment and you have done lot of trouble shooting on hosts with ssh enabled.

In order to maintain the security standard the ssh of the hosts has to be disabled eod. For this the admin has to manually disable the ssh on each hosts. This is some times error prone as you might miss dissabling on one or the other hosts.

The below power cli script will help a vmware admin to search the hosts


I have 3 hosts that have ssh enabled.




1) finding host that are running ssh on it.

$hoststatus=Get-VMHost | Get-VMHostService |where{$_.KEY -eq "TSM-SSH" -and $_.running -eq "True"} | select VMHost, Key, Running


After running the above script dumping the $hostsstatus variable we can see the three esxi hosts showing ssh running as true.


Now we will stop the ssh services of the above hosts.

we would use the same $hoststatus variable to stop the service. so both the script can be used in continuation.


2 stoping ssh hosts

Get-VMHost $hoststatus.vmhost| foreach {Stop-VMHostService -HostService ($_|Get-VMHostService|where{$_.key -eq "tsm-ssh"})}




3) now we will check the status of the service once again bu running the comand in step 1.


we can see there are no hosts shown this time.



4) starting ssh hosts

if we want to start any host service then we can use below command.


Get-VMHost <hostname>| foreach {Start-VMHostService -HostService ($_|Get-VMHostService|where{$_.key -eq "tsm-ssh"})}



232 views0 comments

Recent Posts

See All