Quantcast
Channel: VMware Communities : Blog List - All Communities
Viewing all articles
Browse latest Browse all 3135

Enable SSH Service on ESXi hosts using PowerShell

$
0
0

if we wanting to enable the SSH service on my ESXi hosts.  we could use Host Profiles to enable it but when  decided to PowerShell script .

 

you can use below powershell to enable SSH on all esxi host in cluster .

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

 

manually-start-ssh-service

 

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

esxi-hosts-ssh-warning

 

you can use below powershell to enable SSH on all esxi host in cluster

 

 

######################################################################

 

# 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-PSSnapinvmware.vimautomation.core

connect-viserver-server$vCenter

$VMHost= Get-Cluster-Name$Cluster| Get-VMhost

# Start SSH Server on a Cluster

ForEach($VMhostin$Cluster){

Write-Host-ForegroundColorGREEN "Starting SSH Service on "-NoNewline

Write-Host-ForegroundColorYELLOW "$VMhost"

Get-VMHost| Get-VMHostService| ? {($_.Key -eq"TSM-ssh") -and($_.Running -eq$False)} | Start-VMHostService

}

# Change Startup Policy

ForEach($VMhostin$Cluster){

Write-Host-ForegroundColorGREEN "Setting Startup Policy on "-NoNewline

Write-Host-ForegroundColorYELLOW "$VMhost"

Get-VMHost| Get-VMHostService| where { $_.key -eq"TSM-SSH"} | Set-VMHostService-Policy"On"-Confirm:$false-ea1

}

# Surpress SSH Warning

ForEach($VMhostin$Cluster){

Write-Host-ForegroundColorGREEN "Setting UserVar to supress Shell warning on "-NoNewline

Write-Host-ForegroundColorYELLOW "$VMhost"

Get-VMhost| Get-AdvancedSetting| Where {$_.Name -eq"UserVars.SuppressShellWarning"} | Set-AdvancedSetting-Value"1"-Confirm:$false

}

### End of Script

 

 

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 this script .


Viewing all articles
Browse latest Browse all 3135

Trending Articles