Get-VMWareTools Cmdlet to retrieve VMWare Tools configuration information


Interestingly enough, I was tasked to find out all the VMware Tools version that requires to be updated within the private cloud infrastructure. I thought to myself, great chance to dig around but with the vast amount of VMs in environment. I aren’t thinking of peeking each VM one by one.

Well, this is not something that I usually do with PowerShell posting on TechNet but it is a good display of how powerful PowerShell is when other vendors are also contributing with their own PowerCLI. So I went into this adventure scripting this to make my life easier in reporting what, which and where is broken with out of date VMware Tools.

And as always, I have posted the Get-VMWareTools.psm1 Cmdlet Module on TechNet to share with everyone who is interested.

Download Link – http://gallery.technet.microsoft.com/Get-VMWareTools-Information-290a239e

function Get-VMwareTools {
<#

.SYNOPSIS
    Get the Virtual Machine VMWare Tools Version, Status and Configuration information.
  
.DESCRIPTION   
    Allows the administrator to get the virtual machine VMWare Tools version, version status and configuration information.

.PARAMETER ComputerName

    ALIAS -VI
    This parameter specify host connection to the VMWare Virtual Center

.PARAMETER GuestName

    ALIAS -Guest
    This parameter allows administrator to specify the VM Guest name

.PARAMETER Username

    ALIAS -U
    This parameter allows administrator to specify username to authenticate with the server.

.PARAMETER Password

    ALIAS -P
    This paramter allows administrator to specify the password to authenticate with the server.

.EXAMPLE
    
    This example demostrate how to import the Get-VMWareTools.psm1 module and use the command
    to query the VMWare vCenter for VMWare Tools information on guest virtual machine
    name VM1.

    Import-Module C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Get-VMWareTools.psm1
    Get-VMWareTools -VI VMWarevCenter -U Redmond\VirtualCenterAdministrator -P C0nt0s0 -Guest VM1

    GuestName                  : VM1
    VMHost                     : esx11.redmond.com
    UUID                       : 5070f400-8066-f583-5364-785c6fc346fd
    OperatingSystem            : Microsoft Windows XP Professional (32-bit)
    Version                    : v7
    PowerState                 : PoweredOn
    BootTime                   :
    ToolsInstallerMounted      : False
    ToolsVersion               : 8295
    ToolsVersionStatus         : guestToolsNeedUpgrade
    ToolsBackwardCompatibility : guestToolsSupportedOld
    ToolsRunningStatus         : guestToolsRunning
    SyncTimeWithHost           : False
    ToolsUpgradePolicy         : manual
    AfterPowerOn               : True
    AfterResume                : True
    BeforeGuestStandby         : True
    BeforeGuestShutdown        : True
    BeforeGuestReboot          :
    PendingCustomization       :

.EXAMPLE
    
    This example demostrate how to generate a report of all the VMWare Tools information
    for each virtual machine in VMWare vCenter and export to a CSV file.

    Get-VMWareTools -ComputerName VMWarevCenter | Export-Csv C:\Temp\Get-VMWareTools.csv -NoTypeInformation


.NOTES
    Title   : PowerShell Get VMWare Tools Version
    FileName: Get-VMWareTools.psm1
    Author  : Ryen Kia Zhi Tang
    Date    : 14/10/2013
    Blog    : ryentang.blogspot.com
    Version : 1.0

    Change Log
    16/10/2013 - Added Disconnect-VIServer to disconnect from vCenter cleanly.
                 Added Remove-PSSnapin to remove VMWare PowerShell CLI cleanly.


#>

param(

    [Parameter(
        Mandatory=$True,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('VI')]
    [String] $ComputerName = $env:COMPUTERNAME,

    [Parameter(
        Mandatory=$False,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('U')]
    [String] $Username,

    [Parameter(
        Mandatory=$False,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('P')]
    [String] $Password,

    [Parameter(
        Mandatory=$False,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('Guest')]
    [String] $GuestName

)

    BEGIN {}

    PROCESS {

        # Add VMWare PowerCLI PSSnapin
        Add-PSSnapin VMware.VimAutomation.Core

        # Verify Username and Password parameter is not null and construct PSCredential object for authentication
        if(($Username -ne "") -and ($Password -ne "")){

            # Construct Credential
            $PWD = convertto-securestring $Password -asplaintext -force
            $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$PWD

            # Establish connection using Credential Object
            $Connection = Connect-VIServer -Server $ComputerName -Credential $Credential -Force -Verbose

        # Verify Username and Password parameter is null and use Windows Integrated Authentication
        }else{

            # Establish connection using Windows Integrated Authentication
            $Connection = Connect-VIServer -Server $ComputerName -Force -Verbose
        }

        # Verify GuestName parameter is not null
        if($GuestName -ne "") {

            # Get specific VM Guest
            $Result = Get-VM -Name $GuestName

        }else{

            # Get all VM Guests
            $Result = Get-VM
        }

        # Construct Result
        $Result | Select @{L='GuestName';E={($_.Name)}},
            VMHost,
            @{L='UUID';E={(((($_).ExtensionData).Config).Uuid)}},
            @{L='OperatingSystem';E={((($_).Guest).OSFullName)}},
            Version,
            PowerState,
            @{L='BootTime';E={(((($_).ExtensionData).RunTime).BootTime)}},
            @{L='ToolsInstallerMounted';E={(((($_).ExtensionData).RunTime).ToolsInstallerMounted)}},
            @{L='ToolsVersion';E={(((($_).Guest).ExtensionData).ToolsVersion)}},
            @{L='ToolsVersionStatus';E={(((($_).Guest).ExtensionData).ToolsVersionStatus)}},
            @{L='ToolsBackwardCompatibility';E={(((($_).Guest).ExtensionData).ToolsVersionStatus2)}},
            @{L='ToolsRunningStatus';E={(((($_).Guest).ExtensionData).ToolsRunningStatus)}},
            @{L='SyncTimeWithHost';E={((((($_).ExtensionData).Config).Tools).SyncTimeWithHost)}},
            @{L='ToolsUpgradePolicy';E={((((($_).ExtensionData).Config).Tools).ToolsUpgradePolicy)}},
            @{L='AfterPowerOn';E={((((($_).ExtensionData).Config).Tools).AfterPowerOn)}},
            @{L='AfterResume';E={((((($_).ExtensionData).Config).Tools).AfterResume)}},
            @{L='BeforeGuestStandby';E={((((($_).ExtensionData).Config).Tools).BeforeGuestStandby)}},
            @{L='BeforeGuestShutdown';E={((((($_).ExtensionData).Config).Tools).BeforeGuestShutdown)}},
            @{L='BeforeGuestReboot';E={((((($_).ExtensionData).Config).Tools).BeforeGuestReboot)}},
            @{L='PendingCustomization';E={((((($_).ExtensionData).Config).Tools).PendingCustomization)}}

    }

    END { Disconnect-VIServer -Server $ComputerName -Confirm:$FALSE ; Remove-PSSnapin VMware.VimAutomation.Core }

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s