ESXi5.5 Host Services (vsantraced) non-VMHostService

Sometimes there is a need to stop/start or pull the status of a service that is not listed on a  host when you run the command Get-VMHostService from PowerCLI.

For reference here is what is listed when you run the above command:

Services shown from an esxi5.x host

Services shown from an esxi5.x host

I have had a need to disable the /etc/init.d/vsantraced service to unmount datastores lately and thought I would try to create something on my own to disable the service on a number of hosts.

I haven’t found a way to do it simply with PowerCLI so I decided to use plink.exe (found here) For the following script it is based on having plink in your windows/system32 folder. As a point of reference this script turns SSH on so that plink can login to each host and run the command. Starting with a great foundation for using plink.exe from Alan Renouf’s blog here, started to test starting and stopping the vsantraced service on individual hosts and then changed the current script to run against all hosts found:

This first bit is just something I have saved into a vsantraced.txt file that is referenced in the actual script that is pasted into PowerCLI and run.

/etc/init.d/vsantraced stop

This is the actual script that is pasted into something like PowerShell ISE

**NOTE this has only been tested this against an environment that is NOT currently using VSAN**

**I currently have the first portion commented out as I am typically already connected to my home lab vCenter server**

##--This script is based on having plink.exe(download with putty) in the windows system32 folder--##
##--Use the commented out lines if you haven't connected to a vC yet--##
## $cred = Get-Credential -Message "vCenter or esxi username and password"
## Connect-Viserver vcenterservername -Credential $cred

Add-PSSnapin vmware.vimautomation.core
$command = "**ENTER THE LOCATION OF THE FIRST TXT FILE**\vsantraced.txt"
$esxiHosts = Get-VMHost
$esxicred = Get-Credential -Message "ESXi Host username and password"
foreach ($esxiHost in $esxiHosts) {
$SSHservice = $esxiHost | Get-VMHostService | where {$psitem.key -eq "tsm-ssh"}
if ($SSHservice.Running -eq $False) {
$esxiHost | Get-VMHostService | where {$psitem.key -eq "tsm-ssh"} | Start-VMHostService
Write-Output "yes" | plink.exe -ssh root@$esxihost -P 22 -pw $passwd -m $command
$esxiHost | Get-VMHostService | where {$psitem.key -eq "tsm-ssh"} | Stop-VMHostService -Confirm:$false


**Please note that these scripts are just for reference – use at your own risk** – Standard disclaimer 🙂