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:
This script does all of the above to an entire cluster. Let’s see it in action!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
###################################################################### # Start SSH Service, change Startup Policy, and Suppress SSH Warning # ###################################################################### #Variables $vCenter = "LABVC01.virtuallyboring.com" $Cluster = "Nested ESXi Cluster" ### Start of Script # Load VMware Cmdlet and connect to vCenter Add-PSSnapin vmware.vimautomation.core connect-viserver -server $vCenter $VMHost = Get-Cluster -Name $Cluster | Get-VMhost # Start SSH Server on a Cluster ForEach ($VMhost in $Cluster){ Write-Host -ForegroundColor GREEN "Starting SSH Service on " -NoNewline Write-Host -ForegroundColor YELLOW "$VMhost" Get-VMHost | Get-VMHostService | ? {($_.Key -eq "TSM-ssh") -and ($_.Running -eq $False)} | Start-VMHostService } # Change Startup Policy ForEach ($VMhost in $Cluster){ Write-Host -ForegroundColor GREEN "Setting Startup Policy on " -NoNewline Write-Host -ForegroundColor YELLOW "$VMhost" Get-VMHost | Get-VMHostService | where { $_.key -eq "TSM-SSH" } | Set-VMHostService -Policy "On" -Confirm:$false -ea 1 } # Surpress SSH Warning ForEach ($VMhost in $Cluster){ Write-Host -ForegroundColor GREEN "Setting UserVar to supress Shell warning on " -NoNewline Write-Host -ForegroundColor YELLOW "$VMhost" Get-VMhost | Get-AdvancedSetting | Where {$_.Name -eq "UserVars.SuppressShellWarning"} | Set-AdvancedSetting -Value "1" -Confirm:$false } ### End of Script |