0

Use PowerCLI To Check VMware Tools Status

If you’re running a VMware environment you might be wondering if there was a way to use PowerCLI To Check VMware Tools Status. The reason for checking it through the command line is so you can check the virtual machines in bulk. This can be done in the GUI but this option really isn’t scalable.

VMware Tools GUI status

Screenshot for GUI method

As you can see from my screenshot above, I’m up to date on my windows 10 machine. However, as I mentioned already this method is not scalable at all so this is why I prefer the Powershell PowerCLI method.

Understanding The VM Properties in PowerCLI

I should probably start off by explaining the properties that are available with the Get-VM cmdlet as this will lay down the foundation for what we’re trying to do. Anytime you run the command Get-VM -Name MyComputer it will output that VM along with the default properties of Name, PowerState, NumCPUs and MemoryGB.

There are more properties available but just not available from the default output. Thus we will need to pipe it to FL (or Format-List). That would look like this. Get-VM -Name PAC-WIN1001| fl

 
What I prefer to use when checking what’s available is setting the output into a variable and quickly finding those properties. This way we can use the $VM.Property1.property2 etc..

In our case we’re going to be drilling down to the ExtensionData -> Guest properties and there we will find our vmtools information.

VMware Tools ExtensionData Guest Info

Use PowerCLI To Check VMware Tools Status – Powershell Script

Script Requirements

  • Must have the PowerCLI module installed
  • Must be connected to vCenter server (or individual host) via PowerCLI

Parameters

    -Name

Description: Enter the virtual machine name that’s listed in vcenter

    -InputObject

Description: Allows pipeline input through the Get-VM cmdlet.

Examples

Example 1:
Get-VMToolsStatus -Name VM1, VM2, VM3
 
Example 2:
Get-VM -Name VM1, VM2, VM3 | Get-VMToolsStatus

PowerCLI To Check VMware Tools Status

This script also supports pipeline input

Powershell PowerCLI Script


Function Get-VMToolsStatus {
<#
.SYNOPSIS
    This will check the status of the VMware vmtools status.
    Properties include Name, Status, UpgradeStatus and Version

.NOTES
    Name: Get-VMToolsStatus
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2020-Sep-1

.LINK
    https://thesysadminchannel.com/powercli-check-vmware-tools-status/ -

.EXAMPLE
    Please refer to the -Online version
    help Get-VMToolsStatus -Online

#>

    [CmdletBinding()]
    param(
        [Parameter(
            Position=0,
            ParameterSetName="NonPipeline"
        )]
        [Alias("VM", "ComputerName", "VMName")]
        [string[]]  $Name,


        [Parameter(
            Position=1,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            ParameterSetName="Pipeline"
            )]
        [PSObject[]]  $InputObject
    )

    BEGIN {
        if (-not $Global:DefaultVIServer) {
            Write-Error "Unable to continue.  Please connect to a vCenter Server." -ErrorAction Stop
        }

        #Verifying the object is a VM
        if ($PSBoundParameters.ContainsKey("Name")) {
            $InputObject = Get-VM $Name
        }

        $i = 1
        $Count = $InputObject.Count
    }

    PROCESS {
        if (($null -eq $InputObject.VMHost) -and ($null -eq $InputObject.MemoryGB)) {
            Write-Error "Invalid data type. A virtual machine object was not found" -ErrorAction Stop
        }

        foreach ($Object in $InputObject) {
            try {
                [PSCustomObject]@{
                    Name = $Object.name
                    Status = $Object.ExtensionData.Guest.ToolsStatus
                    UpgradeStatus = $Object.ExtensionData.Guest.ToolsVersionStatus2
                    Version = $Object.ExtensionData.Guest.ToolsVersion
                }
            } catch {
                Write-Error $_.Exception.Message

            } finally {
                if ($PSBoundParameters.ContainsKey("Name")) {
                    $PercentComplete = ($i/$Count).ToString("P")
                    Write-Progress -Activity "Processing VM: $($Object.Name)" -Status "$i/$count : $PercentComplete Complete" -PercentComplete $PercentComplete.Replace("%","")
                    $i++
                } else {
                    Write-Progress -Activity "Processing VM: $($Object.Name)" -Status "Completed: $i"
                    $i++
                }
            }
        }
    }

    END {}
}

 
Hopefully you found some value from this post and can now use this script in your environment. It’s always a good idea to do a basic audit to see what’s not up to standard. Speaking of audit, I would also suggest you take a look at the VMware VM Information Script which will give you specific details on host, cluster, datacenter, datastore, network, IP address etc.. It’s actually pretty neat and yours for the taking.

If you’re more into video learning, be sure to check out our Youtube Channel for sysadmin video content.

5/5 - (12 votes)

Paul Contreras

Hi, my name is Paul and I am a Sysadmin who enjoys working on various technologies from Microsoft, VMWare, Cisco and many others. Join me as I document my trials and tribulations of the daily grind of System Administration.

Leave a Reply

Your email address will not be published.