Thursday, 14 December 2017

Turn ON/OFF SSH on All ESXi host in vCenter/Cluster


$AllEsxi = get-vmhost
$AllEsxi | get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy ON
$Allesxi| Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Start-VMHostService 


Output:-

  • First, we declare a variable $AllEsxi which stores result from Get-VMhost & then we are enabling SSH on all the given hosts.
  • If you want to turn OFF the SSH on all the hosts, simply replace ON with OFF and run the command.
  • To turn off & stop the service on all the host.


$AllEsxi | Get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy OFF
$Allesxi| Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Stop-VMHostService 


  • If you want to do it at Cluster level, then specify the cluster variable or then use the following:-
$Cluster_Host = Get-Cluster MyCluster | Get-VMHost
$Cluster_Host | get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy ON
$Cluster_Host | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Start-VMHostService 

  • If you want to turn ON/OFF service at cluster level, then specify the cluster variable or use the following:-
$Cluster_Host  | Get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy OFF
$Cluster_Host  | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Stop-VMHostService 




    No comments:

    Post a Comment