Check VMware Tools Status

I wanted to perform a mass graceful shutdown of VM’s as part of an orchestrated lift-and-shift effort. When I started my preparation work, which mainly consisted of me testing scripts in my lab environment, it dawned on me that not all of my Production VM’s have VMware Tools installed. So how can I go about checking the VMware Tools Status for each VM?

Here is a quick one-liner to output the status of VMware Tools for all VM’s in the environment:

Get-VM | Select Name,@{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}} 

This will output either “toolsOk”, “toolsOld”,”toolsNotRunning” or ” toolsNotInstalled” (thank you Anton!).

For my shutdown effort, I created a list of VM’s with and without VMware Tools running:

$tools = foreach ($vm in (Get-Cluster "LAB01")) {
    Get-VM $vm | ? {($_.ExtensionData.Guest.ToolsStatus -eq "toolsOk") 
    -or ($_.ExtensionData.Guest.ToolsStatus -eq "toolsOld")}
}

Note the subtle differences between the $tools and $notools blocks.

$notools = foreach ($vm in (Get-Cluster "LAB01")) {
    Get-VM $vm | ? {($_.ExtensionData.Guest.ToolsStatus -ne "toolsOk") 
    -and ($_.ExtensionData.Guest.ToolsStatus -ne "toolsOld")}
}

This allowed me to shutdown the VM’s with Tools installed gracefully, and power off the VM’s without Tools installed:

foreach ($vm in $tools.Name) {
    Get-VM $vm | Stop-VM -Confirm:$false
}
foreach ($vm in $notools.Name) {
    Get-VM $vm | Stop-VM -Confirm:$false
}

2 responses to “Check VMware Tools Status

Leave a Reply

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