Starting or stopping the SSH service on multiple ESXi hosts can be a tedious job when having to do this via the vSphere (Web)Client. Fortunately, you can also use PowerCLI to start/stop services quickly. With a little scripting, you can expand this to start/stop services on a set of hosts, a cluster, or the entire vCenter.
First, start PowerCLI and make a connection to the vCenter. For automation, you can use something like this (note that you have to add code for credentials, if needed):
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { Add-PSSnapin VMware.VimAutomation.Core | Out-Null } Connect-VIServer vcenter.domain.local
Once that's done, you can gather a list of hosts to work on:
$VMHosts = Get-Cluster "MyCluster" | Get-VMHost
To start the SSH service, use the list (array variable $VMHosts) to start the service on:
ForEach ($VMHost in $VMHosts) { Start-VMHostService -HostService (Get-VMHostService -VMHost $VMHost.Name | Where {$_.Key -eq "TSM-SSH"}) }
To stop the SSH service:
ForEach ($VMHost in $VMHosts) { Stop-VMHostService -HostService (Get-VMHostService -VMHost $VMHost.Name | Where {$_.Key -eq "TSM-SSH"}) -Confirm:$false }
Use -Confirm:$false to avoid the confirmation prompt on each host.
« ‹ | December 2024 | › » | ||||
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |