Working with host services

PowerCLI has some cmdlets to work with host services. You can easily find these cmdlets using the Get-Command cmdlet, as follows:

PowerCLI C:> Get-Command -Noun VMHostService

The preceding command has the following output:

CommandType Name                  ModuleName
----------- ----                  ----------
Cmdlet      Get-VMHostService     VMware.VimAutomation.Core
Cmdlet      Restart-VMHostService VMware.VimAutomation.Core
Cmdlet      Set-VMHostService     VMware.VimAutomation.Core
Cmdlet      Start-VMHostService   VMware.VimAutomation.Core
Cmdlet      Stop-VMHostService    VMware.VimAutomation.Core

In the following sections, we will discus the *-VMHostService cmdlets.

Retrieving information about host services

You can use the Get-VMHostService cmdlet to retrieve information about the services running on a host.

The syntax of the Get-VMHostService cmdlet is:

Get-VMHostService [-VMHost] <VMHost[]> [-Refresh] [-Server
    <VIServer[]>] [<CommonParameters>]

The -VMHost parameter is required.

Let's retrieve a list of all of the services of one of the hosts:

PowerCLI C:> Get-VMHostService -VMHost 192.168.0.133


    Key            Label                     Policy Running Required
---            -----                     ------ ------- --------
DCUI           Direct Console UI         on     True    False
TSM            ESXi Shell                off    False   False
TSM-SSH        SSH                       off    False   False
lbtd           Load-Based Teaming Daemon on     True    False
lwsmd          Active Directory Service  off    False   False
ntpd           NTP Daemon                on     True    False
pcscd          PC/SC Smart Card Daemon   off    False   False
sfcbd-watchdog CIM Server                on     True    False
snmpd          SNMP Server               on     False   False
vmsyslogd      Syslog Server             on     True    True
vprobed        VProbe Daemon             off    False   False
vpxa           VMware vCenter Agent      on     True    False
xorg           X.Org Server              on     False   False

Starting a host service

Starting a host service can be useful to temporarily enable a service. For example, if you want to enable the ESXi shell to log in to an ESXi server, you need to start the TSM service. The Start-VMHostService cmdlet will start a host service. The syntax of this cmdlet is as follows:

Start-VMHostService [-HostService] <HostService[]> [-WhatIf] 
    [-Confirm] [<CommonParameters>]

The -HostService parameter is required.

For example, to start the TSM service, you can use the following command:

PowerCLI C:> Get-VMHost -Name 192.168.0.133 | Get-VMHostService |
>> Where-Object {$_.Key -eq "TSM"} | Start-VMHostService
>>


    Key            Label                     Policy Running Required
---            -----                     ------ ------- --------
TSM            ESXi Shell                off    True    False

The command first retrieves host 192.68.0.133. Then, it retrieves all of the services running on the host and selects only the service where the Key property has the value TSM. Finally, it starts the selected service.

Stopping a host service

After you have temporarily enabled a service, you should stop the service if you don't plan to use it anymore. Some services, such as the SSH service, produce a warning if you keep them running. To stop a service, you need to use the Stop-VMHostService cmdlet. The syntax is similar to the Start-VMHostService cmdlet's syntax:

Stop-VMHostService [-HostService] <HostService[]> [-WhatIf]
    [-Confirm] [<CommonParameters>]

The -HostService parameter is required.

To stop the TSM service we started in the preceding section, use the following command line:

PowerCLI C:> Get-VMHost -Name 192.168.0.133 | Get-VMHostService |
>> Where-Object {$_.Key -eq 'TSM'} |
>> Stop-VMHostService -Confirm:$false
>>


    Key            Label                     Policy Running Required
---            -----                     ------ ------- --------
TSM            ESXi Shell                off    False   False

As you can see, the command to stop a host service is similar to the command to start a host service from the preceding section.

Restarting a host service

If you want to restart a host service because it is not running well or you modified the settings of the service, you can use the Restart-VMHostService cmdlet.

The syntax of this cmdlet is as follows:

Restart-VMHostService [-HostService] <HostService[]> [-WhatIf]
    [-Confirm] [<CommonParameters>]

In the following example, we will restart the TSM service. I modified this example, in comparison with the preceding start and stop host services examples, to show you that in PowerCLI there are different ways you can use to perform a task:

PowerCLI C:> $HostService = Get-VMHost -Name 192.168.0.133 |
>> Get-VMHostService | Where-Object {$_.Key -eq 'TSM'}
>> Restart-VMHostService -HostService $HostService -Confirm:$false
>>


    Key            Label                     Policy Running Required
---            -----                     ------ ------- --------
TSM            ESXi Shell                off    True    False

The command from the preceding example saves the host service with Key value TSM in a variable named $HostService. This variable is used as the value of the -HostService parameter in the Restart-VMHostService command to restart the service.

Modifying the startup policy of a host service

You can use the Set-VMHostService cmdlet to modify the startup policy of a host service.

The following screenshot shows you how to edit the startup policy of a host service in the vSphere Web Client:

Modifying the startup policy of a host service

The syntax of the Set-VMHostService cmdlet is:

Set-VMHostService [-HostService] <HostService[]> [-Policy]
    <HostServicePolicy> [-WhatIf] [-Confirm] [<CommonParameters>]

The -HostService and -Policy parameters are required.

Possible values for the -Policy parameter are automatic, on, and off. These values correspond to the following values in the VMware vSphere Client:

VMware vSphere Client service startup policy

Set-VMHostService -Policy value

Start and stop with port usage

automatic

Start and stop with host

on

Start and stop manually

off

Let's modify the startup policy of the TSM service and set it to on. We will use the $HostService variable from the preceding example:

PowerCLI C:> Set-VMHostService -HostService $HostService -Policy on


    Key            Label                     Policy Running Required
---            -----                     ------ ------- --------
TSM            ESXi Shell                on     True    False

In the following example, the startup policy of the TSM service for all of your hosts will be set to off:

PowerCLI C:> Get-VMHost | Get-VMHostService |
>> Where-Object {$_.Key -eq 'TSM'} |
>> Set-VMHostService -Policy Off
>>


    Key            Label                     Policy Running Required
---            -----                     ------ ------- --------
TSM            ESXi Shell                off    True    False
TSM            ESXi Shell                off    False   False
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.27.232