- SolarWinds Server Performance and Configuration Bundle - Tue, Jun 18 2019
- SolarWinds Patch Manager: Updating Windows and third-party software - Tue, Apr 30 2019
- Monitor file changes in Windows with PowerShell and pswatch - Fri, Feb 1 2019
ESXi hosts run a proprietary kernel but allows SSH access that includes various Linux commands. Thus, it certainly helps if sysadmins understand Linux in order to manage and troubleshoot the servers. Fortunately, for VMware admins who are experts only in Windows, PowerCLI can be an option when it comes to many ESXi tasks.
Getting the status of ESXi services
To show the status of services on an ESXi host, we can use the Get-VMHostService cmdlet. This cmdlet has only three unique parameters: -VMHost, -Server, and -Refresh. The -Refresh parameter refreshes data on the service before printing it to the console.
In the example below, I am just showing the current service status on the ESXi host VMHost-1:
C:\ > Get-VMHostService -VMHost VMHost-1 -Refresh 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 True False vmsyslogd Syslog Server on True True vmware-fdm vSphere High Availability A... on True False vprobed VProbe Daemon off False False vpxa VMware vCenter Agent on True False xorg X.Org Server on False False
Starting, stopping and restarting ESXi services
In the next example, I will show how to use PowerCLI to start and stop ESXi services. First, we need to place the VMhost and service we want to manage into a variable in PowerShell.
Here, I want to start the SSH service, so I use Get-VMHostService to specify the host and service:
C:\Windows\System32> $VMHostService = Get-VMHostService -VMHost VMHost-1 -Refresh | Where {$_.Key -eq 'TSM-SSH'}
Now, I simply use the $VMHostService variable with Start-VMHostService to start the SSH service:
C:\Windows\System32> Start-VMHostService -HostService $VMHostService
If I would like to restart the SSH service, I just specify the Restart-VMHostService cmdlet along with the same PowerShell variable:
C:\Windows\System32> Restart-VMHostService -HostService $VMHostService -Verbose VERBOSE: 10/9/2017 4:33:25 PM Restart-VMHostService Started execution Perform operation? Perform operation Restart host service. on SSH? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): a Key Label Policy Running Required --- ----- ------ ------- -------- TSM-SSH SSH off True False VERBOSE: 10/9/2017 4:33:27 PM Restart-VMHostService Finished execution
Modifying ESXi services
To modify the policy on a specific service, we use Set-VMHostService. Again, we will specify the same ESXi SSH service, but instead of the default policy of not having the service running, we will enable it to be On, meaning it will start the service upon boot.
C:\Windows\System32> Get-VMHostService -VMHost VMHost-1 -Refresh | Where {$_.Key -eq 'TSM-SSH'} | Set-VMHostService -Policy On Key Label Policy Running Required --- ----- ------ ------- -------- TSM-SSH SSH on True False
Automating bulk changes to ESXi services
One of the great features of PowerShell, and thus PowerCLI, is the ability to automate a time-consuming task. For instance, if we would like to set all ESXi services on all of our hosts in the cluster so the Active Directory service is On, we can do this with one line of PowerShell.
First, we connect to our vCenter from PowerCLI:
C:\Windows\System32> Connect-VIServer vcenter
Now, we pipe the results of Get-VMHostService using a wildcard to find all VMHosts in the cluster to Set-VMHostService using -Policy On:
Subscribe to 4sysops newsletter!
C:\Windows\System32> Get-VMHostService -VMHost * -Refresh | Where {$_.Key -eq 'lwsmd' } | Set-VMHostService -Policy On
Within seconds, all VMHosts in the cluster have the Active Directory service running.
Good info but ESXi is not linux based 🙂
Gabe, ESXi uses a Linux kernel.
yup , vmkernel totally linux based which manage / control esxi
I’m sorry but you’re both wrong. As of 4.1, ESXi has its own VMware developed micro kernel that’s is NOT Linux based. When you SSH into a host, you’re actually using a BusyBox shell that includes a lot of the commands you recognize from Linux.
From VMware themselves: https://blogs.vmware.com/vsphere/2013/06/its-a-unix-system-i-know-this.html
Look up FACTS before randomly saying things without knowing for SURE. It’s dangerous to live otherwise.
Gabe, I actually looked this up. This Wikipedia article claims that a Linux kernel is loaded first and then comes the vmkernel:
Yes, Michael, that was true for ESX, not ESXi. if you look later in that paragraph it says:
“VMware dropped development of ESX at version 4.1, and now uses ESXi, which does not include a Linux kernel.”
Oh yes, I missed that. Thanks for clearing this up! 🙂
Personally I thought it was Linux based. In any case we can consider ESXi as Unix-like operating system. Also today I learned something new.
Ive updated the post to reflect that ESXi is not linux-based.
Awesome Dan!
BusyBox: The Swiss Army Knife of Embedded Linux
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.
BusyBox has been written with size-optimization and limited resources in mind. It is also extremely modular so you can easily include or exclude commands (or features) at compile time. This makes it easy to customize your embedded systems. To create a working system, just add some device nodes in /dev, a few configuration files in /etc, and a Linux kernel.
https://busybox.net/about.html