Start/Stop Tech Support Mode on vSphere hosts

After the installation of the latest vSphere 4.1 patches all hosts displayed a warning about Local & Remote Tech Support Mode being enabled. As I didn’t file like manually stopping the services on every host I took the time to write a script which can start/stop Local and Remote Tech Support mode on all hosts in a vCenter.

<#
 .SYNOPSIS
 Start or Stop Local & Remote TSM
 .VERSION
 1.0
 .DESCRIPTION
 Script to start or stop Local & Remote Tech Support Mode on all the vSphere severs located in vCenter.
 .NOTES
 Author(s): Stijn Vermoesen
 .EXAMPLE
 PS> ./StartStop-TSM.ps1
 #>

### Check if the VMware PowerCLI plugin is loaded
 if ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
 {
 Add-PSSnapin VMware.VimAutomation.Core
 Write-Host "Loading VMware PowerCLI Powershell plugin." -ForegroundColor blue
 }
 else
 {
 Write-host "VMware PowerCLI Powershell plugin already loaded." -ForegroundColor blue
 }

$vCenter = Read-Host "Provide vCenter Server"

# Connect to the vCenter server
 Connect-VIServer $vCenter -credential ( Get-Credential )

$serviceInstance = get-view ServiceInstance
 if ( $serviceInstance.content.about.Name -like "Vmware vCenter Server")
 {

$vmhosts = Get-VMHost | sort Name

Write-Host "Start or to stop the Remote Tech Support (SSH)service"
 Write-Host "The Tech Support services on ALL hosts in the vCenter will be changed by running this script." -ForegroundColor Magenta
 Write-Host " 1) Start Remote Tech Support (SSH)"
 Write-Host " 2) Stop Remote Tech Support (SSH)"
 Write-Host " 3) Start Local Tech Support (DCUI)"
 Write-Host " 4) Stop Local Tech Support (DCUI)"
 Write-Host " 5) Start Local & Remote Tech Support (DCUI & SSH)"
 Write-Host " 6) Stop Local & Remote Tech Support (DCUI & SSH)"
 $response = Read-Host "Enter your selection"

foreach ($vmhost in $vmhosts)
 {

Switch ($response)
 {
 1 {
 $vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | %{
 if ($_.running -eq $false) {
 $_ | Start-VMHostService -Confirm:$false | Out-Null
 Write-Host "Remote Tech Support Mode on $vHost started"
 }
 else {
 Write-Warning "Remote Tech Support Mode on $vHost already started"}
 }
 }

2{
 $vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | %{
 if ($_.running -eq $true) {
 $_ | Stop-VMHostService -Confirm:$false | Out-Null
 Write-Warning "Remote Tech Support Mode on $vHost stopped"}
 }
 else {
 Write-Host "Remote Tech Support Mode on $vHost already stopped"
 }
 }

3{
 $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"} |  %{
 if ($_.running -eq $false) {
 $_ | Start-VMHostService -Confirm:$false | Out-Null
 Write-Host "Local Tech Support Mode on $vHost started"
 }
 else {
 Write-Warning "Local Tech Support Mode on $vHost already started"}
 }

}

4{
 $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"} | %{
 if ($_.running -eq $true) {
 $_ | Stop-VMHostService -Confirm:$false | Out-Null
 Write-Warning "Local Tech Support Mode on $vHost stopped"}
 }
 else {
 Write-Host "Local Tech Support Mode on $vHost already stopped"
 }
 }

5{
 $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"}| %{
 if ($_.running -eq $false) {
 $_ | Start-VMHostService -Confirm:$false | Out-Null
 Write-Host "Local Tech Support Mode on $vHost started"
 }
 else {
 Write-Warning "Local Tech Support Mode on $vHost already started"}
 }

$vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | %{
 if ($_.running -eq $false) {
 $_ | Start-VMHostService -Confirm:$false | Out-Null
 Write-Host "Remote Tech Support Mode on $vHost started"
 }
 else {
 Write-Warning "Remote Tech Support Mode on $vHost already started"}
 }
 }

6{
 $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"}| %{
 if ($_.running -eq $true) {
 $_ | Stop-VMHostService -Confirm:$false | Out-Null
 Write-Host "Local Tech Support Mode on $vHost stopped"
 }
 else {
 Write-Warning "Local Tech Support Mode on $vHost already stopped"}
 }

$vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | %{
 if ($_.running -eq $true) {
 $_ | Stop-VMHostService -Confirm:$false | Out-Null
 Write-Host "Remote Tech Support Mode on $vHost stopped"
 }
 else {
 Write-Warning "Remote Tech Support Mode on $vHost already stopped"}
 }
 }

default {
 Write-Host "Enter a valid number (1-6)"
 }
 }
 }
 }
 else
 {
 Write-Error "This script should be run against a vCenter server"
 }
 Disconnect-VIServer    -Confirm:$false
Posted in PowerShell, Scripting, Virtualization
IT Pro Summer GP
IT Pro Summer Grand Prix
MVA
Microsoft Virtual Academy
Pro-Exchange
Pro-Exchange / Pro-Lync / Pro-Office365
MEET

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 158 other followers

%d bloggers like this: