PowerCli – Start SSH Service, change Startup Policy, and Suppress SSH Warning

Loading

#####################################################################
# Start SSH Service, change Startup Policy, and Suppress SSH Warning #
# Tested by Ash on 28 Oct
# V1.0
######################################################################

$env:PSModulePath
#Import Core Module  - if not sure why this isn't working then go watch 
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

Add-PSSnapin vmware.vimautomation.core
Import-Module VMware.VimAutomation.core
Import-MOdule VMware.VimAutomation.Common

$credVC = get-credential administrator@vsphere.local
#$credESX = get-credential root
$vcenter = Connect-VIServer -Server sfo-m01-vc02.ash.local -Credential $credVC
$Cluster = "Compute"
  
### 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

# Pause for user input
pause 

# 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


(Visited 308 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