Enable SSH Service on ESXi hosts using PowerShell

I found myself wanting to enable the SSH service on my ESXi hosts. I could use Host Profiles to enable it but I decided to PowerShell script it! To enable SSH there are three parts to it:

You will need to start the SSH service and set it to Start and Stop with Host:

And you will need to suppress the SSH is enabled warning message:

esxi-hosts-ssh-warning

This script does all of the above to an entire cluster. Let’s see it in action!

Paste the script in PowerShell ISE as we need to update a few variables:

  1. $vCenter: Enter your vCenter name of your vCenter name
  2. $Cluster: Enter the name of your Cluster

You are now ready to run the script!

4 thoughts on “Enable SSH Service on ESXi hosts using PowerShell”

  1. This worked like a champ, however I’m using PowerCLI 6.5 and I got an error on this:
    Add-PSSnapin vmware.vimautomation.core

    Reply
  2. There’s quite some redundancy and unnecessary stuff in your scipt. Basically you can compress lines 14-35 to this:

    Get-Cluster -Name $Cluster | Get-VMhost | %{
    Write-Host -ForegroundColor YELLOW “Proeccsing $_”
    Write-Host -ForegroundColor GREEN “Starting SSH Service”
    $_ | Get-VMHostService | ? {($_.Key -eq “TSM-ssh”) -and ($_.Running -eq $False)} | Start-VMHostService

    Write-Host -ForegroundColor GREEN “Setting Startup Policy”
    $_ | Get-VMHostService | where { $_.key -eq “TSM-SSH” } | Set-VMHostService -Policy “On” -Confirm:$false -ea 1

    Write-Host -ForegroundColor GREEN “Setting UserVar to supress Shell warning”
    $_ | Get-AdvancedSetting | Where {$_.Name -eq “UserVars.SuppressShellWarning”} | Set-AdvancedSetting -Value “1” -Confirm:$false
    }

    Reply
  3. Worked awesome, thanks!!!

    I would add a line at the bottom:

    Disconnect-VIServer -Server $vCenter -Confirm:$false

    This way you don’t end up with multi-sessions open.

    Reply

Leave a Reply