This PowerCLI Script makes it easy to manage SSH ON/OFF for all hosts at once or a single selected host from a menu.

# SSH Manager can turn SSH for all hosts or a single host ON or OFF. 


Function Login {
    Clear-Host
    Write-Host "vCenter Server: " -ForegroundColor Green -NoNewline
    $vServer = Read-Host 
    $credential = Get-Credential
    Connect-VIserver -Server $vServer -Credential $credential

    if (!$defaultVIServer) {
            Clear-Host
            Write-Host "Invalid Login" -ForegroundColor red | PressAnyKey | Login
        } else {
            Write-Host "Login Success!" -ForegroundColor Green | PressAnyKey
        }
}

Function SSHMenu 
	{
    Clear-Host
    Write-Host "MAIN MENU" -ForegroundColor DarkGreen
    Get_Status
    Write-Host
    Write-Host "Turn SSH:  " -NoNewline
    Write-Host "[1] On For ALL  " -ForegroundColor Green -NoNewline
    Write-Host "[0] Off For ALL  " -ForegroundColor Red -NoNewLine
    Write-Host "[T]ogggle Single Host  " -NoNewLine
    Write-Host "[Q]uit  "-ForegroundColor Yellow -NoNewLine
    Write-Host ": "-NoNewline
    $ssh = Read-Host 

    switch ($ssh) {
        1 {  
            SSH_On
            Get_Status 
            SSHMenu      
        }
        0 {
            SSH_Off
            Get_Status
            SSHMenu        
        }
        T{
            Single_Host
            Get_Status
            SSHMenu
        }
        Q {
            fn_Quit
        }
        Default {
            Write-Host "Invalid Entry" -ForegroundColor Red -BackgroundColor Yellow
            PressAnyKey
            Get_Status
            SSHMenu
        }
    }
}
Function PressAnyKey {
    Write-Host "Press Any Key to Continue..." -ForegroundColor Yellow -NoNewLine
    Read-Host
}

Function SSH_ON {

    $allHosts = Get-VMHost
    foreach ($VMHost in $allHosts ) {
        $VMhost | Get-VmHostService | Where-Object {$_.key -eq "TSM-SSH"} | Start-VMHostService -Confirm:$false
    }

}

Function SSH_Off {
    $allHosts = Get-VMHost
    foreach ($VMHost in $allHosts ) {
        $VMhost | Get-VmHostService | Where-Object {$_.key -eq "TSM-SSH"} | Stop-VMHostService -Confirm:$false
    }   
}

Function Single_Host {
    $i=0
    Clear-Host
    Write-Host "TOGGLE SINGLE HOST" -ForegroundColor Yellow
    Get_Status
    Write-Host
    Write-Host "Enter Host # To Toggle ON/OFF  " -NoNewline
    Write-Host "[M]ain Menu  " -ForegroundColor Yellow -NoNewline
    Write-Host "[Q]uit: " -ForegroundColor Red -NoNewline
    $hostNumber = Read-Host 
    if ($hostNumber -eq "M") {SSHMenu} 
    if ($hostNumber -eq "Q") {fn_Quit} 
    $foundHost="1"
    $allHosts = Get-VMHost
    foreach ($VMHost in $allHosts ) {
        $i++
        if ($i -eq $hostNumber) {
            $foundHost="0"
            $serviceStatus = Get-VMHostService -VMHost $VMHost | Where-Object {$_.Key -eq "TSM-SSH"} | Select-Object Running
            if ($serviceStatus.Running) {
                Write-Host $VMHost "Service is ON so STOPPPING" -ForegroundColor Red
                $VMhost | Get-VmHostService | Where-Object {$_.key -eq "TSM-SSH"} | Stop-VMHostService -Confirm:$false
                Single_Host
                } else {
                    Write-Host $VMHost "Service is OFF so STARTING" -ForegroundColor Green
                    $VMhost | Get-VmHostService | Where-Object {$_.key -eq "TSM-SSH"} | Start-VMHostService -Confirm:$false
                    Single_Host
            }
            
        }
    }  
    if ($foundHost -eq "1") {Write-Host "Server Not Found" -ForegroundColor Red | PressAnyKey | Single_Host}
}

Function fn_Quit  {
    Disconnect-VIServer -Server * -Force -Confirm:$false
    Write-Host "Finished"
    exit
}

Function Get_Status {
    Write-Host 
    Write-Host "Current Host Status:" -ForegroundColor Green
    Write-Host "Host # `t Host SSH Status" -ForegroundColor Yellow
    $VMHost = Get-VMHost
    $i=0
    foreach ($VMHost in $VMHost) {
        $i++
         $serviceStatus = Get-VMHostService -VMHost $VMHost | Where-Object {$_.Key -eq "TSM-SSH"} | Select-Object Running
         if ($serviceStatus.Running) {
            $sshStatus = "ON"
            $fgColor = "Green"
        } else {
            $sshStatus = "OFF"
            $fgColor = "Red"
        }
         Write-Host $i "`t" $VMHost" " -NoNewLine
         Write-Host $sshStatus -ForegroundColor $fgColor
        
    }
}
    $host.UI.RawUI.ForegroundColor = "White"
    $host.UI.RawUI.BackgroundColor = "Black"
    Login
    Clear-Host
    SSHMenu