Disable or Enable SSH on an VMware ESXi host

Using PowerCLI, Connect to vCenter and start or stop the SSH service on a host._x000A_Notet that , the computer running this script must have PowerCLI, and vCenter credentails are required during script execution.

Version: 1.2.25
Created: 2019-10-04T14:29:03.103
Modified: 2019-10-04T21:25:19.843
Creator: mc
Downloads: 33
Tags:
The Script Copy Script Copied to clipboard

<# .NAME: Disable or Enable SSH on an VMware ESXi host Using PowerCLI, Connect to vCenter and start or stop the SSH service on a host. The computer running this script requires PowerCLI and vCenter credentails will be PROMPTED .CREDITS: https://vmguru.com/2016/01/powershell-friday-enabling-ssh-with-powercli/ .AUTHOR: Marcel Calef 2019-10-04 .TAGS: $HypervisorPlatform="VMware" #>

$sshDesired = $args[0]
$hypervisor = $args[1]
$input= $args[2] ; $p1,$p2,$vCenter,$sdk= $input.split(‘/’) ## Remove the https:// and /sdk
$ESXhost = $args[3]

# Checks
If ($hypervisor -ne “VMware”) { Write-host “This script is designed for VMware ESXi hosts only” ; exit }

Connect-VIServer $vCenter # Credentials will be prompted

Get-VMHostService -VMHost “$ESXhost” | Where-Object {$_.Key -eq “TSM-SSH”} # list current state

if ($sshDesired -eq “Stop”) {Get-VMHostService -VMHost “$ESXhost” | Where-Object {$_.Key -eq “TSM-SSH”} | Stop-VMHostService -Confirm:$false}
if ($sshDesired -eq “Start”) {Get-VMHostService -VMHost “$ESXhost” | Where-Object {$_.Key -eq “TSM-SSH”} | Start-VMHostService -Confirm:$false}

START YOUR TRIAL

Get Your Download Link

Gain access to ControlUp from your PC. Register and get a link to start your Free Trial.