Managing services on esxi host systems from powercli, starting tsm-ssh

What if you wanted to check status of some particular service on the host system. For example, you need to login via ssh to all of your esxi boxes in myCluster1.
Let’s check status of remote Tech support ssh service

Get-Cluster -Name "myCluster1" | get-vmhost | Get-VMHostService | ? {$_.Key -eq "TSM-ssh"}
Key                  Label                          Policy     Running  Required
---                  -----                          ------     -------  --------
TSM-SSH              Remote-Support (SSH)           off        True     False
TSM-SSH              Remote-Support (SSH)           off        False    False
TSM-SSH              Remote-Support (SSH)           off        False    False

This is the default output. We do not see on which host the ssh is turned on or off
We can quickly add it to our output:

Get-Cluster -Name "myCluster1" | get-vmhost | % {$vhost=$; get-VMHostSErvice -VMHost $_ | ? {$_.Key -eq "TSM-ssh"}|select @{N="Host";E={$vhost}}, @{N="Service";E={$_.Key}},Running,Policy }

Host                   Service        Running Policy
----                   -------        ------- ------
host1                  TSM-SSH          True off
host2                  TSM-SSH          True off
host3                  TSM-SSH          True off

Above line will do what is needed, but i just realized that this not efficient as there is no need to do this approach. VMhost property is included in each service object. So we can just simply use below line.

Get-Cluster -Name "UPCAT WIN CLuster" | get-vmhost | Get-VMHostService | ? {($_.Key -eq "TSM-ssh")} |select VMHost, Key,Label, Running

To check what servieces are avaialable on host :

get-vmhost "vmhost1" |Get-VMHostService|select Key,Label

Now if you want to start for example TSM-SSH service, for all hosts in cluster

Get-Cluster -Name "myCluster1" | get-vmhost | Get-VMHostService | ? {($_.Key -eq "TSM-ssh") -and ($_.Running -eq $False)} | Start-VMHostService

So we are looking for tesm-ssh services wich are not currently running and piping them to Start-VMHostSErvice.

As you can see it is very easy to manipulate host system services from powercli.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s