I alluded to this in another post but couldn’t find it when I was searching my posts for the cmdlet. So here’s a separate post.
The Get-VMHostService
is your friend when dealing with services on ESXi hosts. You can use it to view the services thus:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
PowerCLI> Get-VMHostService ESX02.rakhesh.local Key Label Policy Running Required --- ----- ------ ------- -------- DCUI Direct Console UI on True False TSM ESXi Shell off True False TSM-SSH SSH automatic True False lbtd lbtd on True False lsassd Local Security Authenticati... off False False lwiod I/O Redirector (Active Dire... off False False netlogond Network Login Server (Activ... off False False ntpd NTP Daemon on True False sfcbd-watchdog CIM Server on True False snmpd snmpd on False False vprobed vprobed off False False vpxa vpxa on True False xorg xorg on False False |
To start and stop services we use the Start-VMHostService
and Stop-VMHostService
but these take (an array of) HostService
objects. HostService
objects are what we get from the Get-VMHostService
cmdlet above. Here’s how you stop the SSH & ESXi Shell services for instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
PowerCLI> Get-VMHostService ESX02.rakhesh.local | ?{ $_.Key -match "TSM" } | Stop-VMHostService Perform operation? Perform operation Stop host service. on ESXi Shell? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Key Label Policy Running Required --- ----- ------ ------- -------- TSM ESXi Shell off False False Perform operation? Perform operation Stop host service. on SSH? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): TSM-SSH SSH automatic False False |
Since the cmdlet takes an array, you can give it HostService
objects of multiple hosts. Here’s how I start SSH & ESXi Shell for all hosts:
1 2 3 4 5 6 7 8 9 10 |
PowerCLI> Get-VMHost | Get-VMHostService | ?{ $_.Key -match "TSM" } | Start-VMHostService Key Label Policy Running Required --- ----- ------ ------- -------- TSM ESXi Shell off True False TSM-SSH SSH off True False TSM ESXi Shell off True False TSM-SSH SSH automatic True False TSM ESXi Shell off True False TSM-SSH SSH automatic True False |
As an aside here’s a nice post on six different ways to enable SSH on a host. Good one!