PowerCli – Ensure SSH is disabled on esx hosts

Loading

In this blog, we will ensure we disable SSH access on all our esx hosts

#####################################################################
# Ensure SSH is disabled #
# Tested by Ash on 28 Oct
# V1.0
######################################################################
  
#Variables
$vCenter = "sfo-m01-vc02.ash.local"
$Cluster = "Production-vSAN"
  
### 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

# Check if SSH is running and set to start 
Get-VMHost | Get-VMHostService | Where { $_.key -eq "TSM-SSH" } | Select VMHost, Key, Label, Policy, Running, Required | ft
# Pause for user input
pause 

  
# Set SSH to start manually rather than automatically for all hosts
ForEach ($VMhost in $Cluster){
Write-Host -ForegroundColor GREEN "Disable SSH Service on " -NoNewline
Write-Host -ForegroundColor YELLOW "$VMhost"
Get-VMHost | Get-VMHostService | Where { $_.key -eq "TSM-SSH" } | Set-VMHostService -Policy Off
}

### End of Script

(Visited 73 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.

Leave a Reply