Script: How to Start, Stop, Restart services on VMware vSphere ESXi server via PowerCLI or using PowerShell

This is a quick post on how to Start, Stop, Restart services on VMware vSphere ESXi server via PowerCLI or using PowerShell.

The service you will need to start or stop simultaneously on multiple servers is likely to be the SSH (TSM-SSH) service.

Here is how you do it with PowerShell / PowerCLI:

$vCenter​​ =​​ 'lab-vc01.lab.local' ​​​​ #Name or IP address of your vCenter Server

$Cluster​​ =​​ 'lab-esxi01.lab.local'​​ #Name of the cluster

Connect-VIServer​​ $vCenter

$Scope​​ =​​ Get-Cluster​​ $Cluster​​ |​​ Get-VMHost

foreach​​ ($ESXhost​​ in​​ $Scope){

Get-VMHost​​ -name​​ $ESXhost​​ |​​ Get-VMHostService​​ |​​ where​​ {$_.key​​ -eq​​ 'TSM-SSH'}​​ |​​ Start-VMHostService​​ -Confirm:$false

 

# Change the line above with the following:

# Start-VMHostService

# Stop-VMHostService

# Restart-VMHostService

 

}

Disconnect-VIServer​​ -Server​​ $vCenter​​ -Confirm:$false

 

## Should you need to start / stop or restart other services, just change the service key.

 

## Here is the list of services:

 

 

Get-VMHost​​ -name​​ lab-esxi01.lab.local​​ |​​ Get-VMHostService​​ |​​ ft​​ -a ​​​​ 

 

 

Key           

Label                                                          

Policy

Running

Required

DCUI          

Direct Console UI                                              

on    

True   

False   

TSM           

ESXi Shell                                                     

off   

False  

False   

TSM-SH       

SSH                                                            

off   

False  

False   

lbtd          

lbtd                                                           

on    

True   

False   

lsassd        

Local Security Authentication Server (Active Directory Service)

off   

False  

False   

lwiod         

I/O Redirector (Active Directory Service)                      

off   

False  

False   

netlogond     

Network Login Server (Active Directory Service)                

off   

False  

False   

ntpd          

NTP Daemon                                                     

on    

True   

False   

sfcbd-watchdog

CIM Server                                                     

on    

True   

False   

vmware-fdm    

vSphere High Availability Agent                                

on    

True   

False   

vpxa          

vpxa                                                           

on    

True   

FALSE

 

$vCenter = 'lab-vc01.lab.local'  #Name or IP address of your vCenter Server
$Cluster = 'lab-esxi01.lab.local' #Name of the cluster
Connect-VIServer $vCenter
$Scope = Get-Cluster $Cluster | Get-VMHost
foreach ($ESXhost in $Scope){
Get-VMHost -name $ESXhost | Get-VMHostService | where {$_.key -eq 'TSM-SSH'} | Start-VMHostService -Confirm:$false

# Change the line above with the following:
# Start-VMHostService
# Stop-VMHostService
# Restart-VMHostService

}
Disconnect-VIServer -Server $vCenter -Confirm:$false

## Should you need to start / stop or restart other services, just change the service key.

## Here is the list of services:


Get-VMHost -name lab-esxi01.lab.local | Get-VMHostService | ft -a  

You May Also Like

About the Author: VirtuallyThatGuy

Leave a Reply

Your email address will not be published. Required fields are marked *