Powercli script to start/stop Local/Remote Tech Support Mode

Share on:

After the installation of the latest vSphere 4.1 patches all our hosts showed a warning regarding the Tech Support Modes being enabled. I took the time to write a script to start/stop theses services on the hosts in the vCenter server.

Image not found

Web path: http://k0v3.files.wordpress.com/2012/03/vcentertsmwarning3.jpg

Disk path: /static/http://k0v3.files.wordpress.com/2012/03/vcentertsmwarning3.jpg

Using Page Bundles: false

  1#  
  2# .SYNOPSIS  
  3# Start or Stop Local & Remote TSM  
  4# .VERSION  
  5# 1.0  
  6# .DESCRIPTION  
  7# Script to start or stop Local & Remote Tech Support Mode on all the
  8# vSphere severs located in vCenter.  
  9# .NOTES  
 10# Author(s): Stijn Vermoesen  
 11# .EXAMPLE  
 12# ./StartStop-TSM.ps1  
 13#
 14
 15### Check if the VMware PowerCLI plugin is loaded  
 16if ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )  
 17{  
 18    Add-PSSnapin VMware.VimAutomation.Core  
 19    Write-Host "Loading VMware PowerCLI Powershell plugin." -ForegroundColor blue  
 20}  
 21else  
 22{  
 23    Write-host "VMware PowerCLI Powershell plugin already loaded." -ForegroundColor blue  
 24}
 25
 26$vCenter = Read-Host "Provide vCenter Server"
 27
 28\# Connect to the vCenter server  
 29Connect-VIServer $vCenter -credential ( Get-Credential )
 30
 31$serviceInstance = get-view ServiceInstance  
 32if ( $serviceInstance.content.about.Name -like "Vmware vCenter Server") {
 33
 34    $vmhosts = Get-VMHost | sort Name
 35
 36    Write-Host "Start or to stop the Remote Tech Support (SSH)service"  
 37    Write-Host "The Tech Support services on ALL hosts in the vCenter will
 38be changed by running this script." -ForegroundColor Magenta  
 39    Write-Host " 1) Start Remote Tech Support (SSH)"  
 40    Write-Host " 2) Stop Remote Tech Support (SSH)"  
 41    Write-Host " 3) Start Local Tech Support (DCUI)"  
 42    Write-Host " 4) Stop Local Tech Support (DCUI)"  
 43    Write-Host " 5) Start Local & Remote Tech Support (DCUI & SSH)"  
 44    Write-Host " 6) Stop Local & Remote Tech Support (DCUI & SSH)"  
 45    $response = Read-Host "Enter your selection"
 46
 47    foreach ($vmhost in $vmhosts) {
 48
 49        Switch ($response) {  
 50            1 {  
 51                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | % {  
 52                    if ($_.running -eq $false) {  
 53                        $_ | Start-VMHostService -Confirm:$false | Out-Null  
 54                        Write-Host "Remote Tech Support Mode on $vHost started"  
 55                    }  
 56                    else {  
 57                        Write-Warning "Remote Tech Support Mode on $vHost already started"
 58                    }  
 59                }  
 60            }
 61
 62            2 {  
 63                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | % {  
 64                    if ($_.running -eq $true) {  
 65                        $_ | Stop-VMHostService -Confirm:$false | Out-Null  
 66                        Write-Warning "Remote Tech Support Mode on $vHost stopped"
 67                    }  
 68                }  
 69                else {  
 70                    Write-Host "Remote Tech Support Mode on $vHost already stopped"  
 71                }  
 72            }
 73
 74            3 {  
 75                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"} | % {  
 76                    if ($_.running -eq $false) {  
 77                        $_ | Start-VMHostService -Confirm:$false | Out-Null  
 78                        Write-Host "Local Tech Support Mode on $vHost started"  
 79                    }  
 80                    else {  
 81                        Write-Warning "Local Tech Support Mode on $vHost already started"
 82                    }  
 83                }
 84
 85            }
 86
 87            4 {  
 88                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"} | % {  
 89                    if ($_.running -eq $true) {  
 90                        $_ | Stop-VMHostService -Confirm:$false | Out-Null  
 91                        Write-Warning "Local Tech Support Mode on $vHost stopped"
 92                    }  
 93                }  
 94                else {  
 95                    Write-Host "Local Tech Support Mode on $vHost already stopped"  
 96                }  
 97            }
 98
 99            5 {  
100                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"}| % {  
101                    if ($_.running -eq $false) {  
102                        $_ | Start-VMHostService -Confirm:$false | Out-Null  
103                        Write-Host "Local Tech Support Mode on $vHost started"  
104                    }  
105                    else {  
106                        Write-Warning "Local Tech Support Mode on $vHost already started"
107                    }  
108                }
109
110                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | % {  
111                    if ($_.running -eq $false) {  
112                        $_ | Start-VMHostService -Confirm:$false | Out-Null  
113                        Write-Host "Remote Tech Support Mode on $vHost started"  
114                    }  
115                    else {  
116                        Write-Warning "Remote Tech Support Mode on $vHost already started"
117                    }  
118                }  
119            }
120
121            6 {  
122                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM"}| % {  
123                    if ($_.running -eq $true) {  
124                        $_ | Stop-VMHostService -Confirm:$false | Out-Null  
125                        Write-Host "Local Tech Support Mode on $vHost stopped"  
126                    }  
127                    else {  
128                        Write-Warning "Local Tech Support Mode on $vHost already stopped"
129                    }  
130                }
131
132                $vmhost | Get-VMHostService | Where {$_.key -eq "TSM-SSH"} | % {  
133                    if ($_.running -eq $true) {  
134                        $_ | Stop-VMHostService -Confirm:$false | Out-Null  
135                        Write-Host "Remote Tech Support Mode on $vHost stopped"  
136                    }  
137                    else {  
138                        Write-Warning "Remote Tech Support Mode on $vHost already stopped"
139                    }  
140                }  
141            }
142
143            default {  
144                Write-Host "Enter a valid number (1-6)"  
145            }  
146        }  
147    }  
148}  
149else {  
150    Write-Error "This script should be run against a vCenter server"  
151}  
152Disconnect-VIServer -Confirm:$false