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