Skip to content

VMware | PowerCLI SSH

A short description about enabling/disabling SSH in bulk within vSphere Environment. At first we are going to figure out which hosts already have SSH enabled (or disabled) afterwards we disable (or enable) it.

Make sure PowerCLI is already installed, otherwise have a look at my other Post: PowerShell | VMware Module

PowerShell
#connect to your vserver, determine you have the necessary credentials/permissions
connect-viserver "your vcenter server"

<#
then we only want the hosts which are Powered on
afterwards we are looking to the service TSM-SSH, if its enabled we are going to disable it.
then we are going to stop the service
#>
get-vmhost |?{$_.PowerState -eq "PoweredOn"}|foreach{
    $ssh = Get-VMHostService -VMHost $_.Name |?{
        $_.key -eq "TSM-SSH"
    }
    if($ssh.Running -eq $true){ #replace $true with $false if you want to enable it
        $ssh | Set-VMHostService -Policy off | stop-VMHostService -Confirm:$false #set the policy to "on" and replace stop-vmhostservice with start-wmvhostservice
        Write-Host "ssh disbled for $_.name" #or enabled... just an output to get the host on which we disabled/enabled ssh
    }
}

Cheers!