VMware Tools one-liners using PowerCli

VMware Tools one-liners using PowerCli

Post source Pario

This short post is about VMware Tools on VM guests running in a vSphere 5.x cluster/hosts.

“Connect by using integrated authentication. In this case, the credentials you are logged on to your machine must be the same as those for the server”

Connect-VIServer Server

This PowerCli one-liner creates a list of VM guests where the VMware Tools CDROM/ISO is mounted:

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {$_.Name}

Unmount the VMware Tools installer CDROM on all VM guests. This is useful to run before you try to put at ESXi host in maintenance mode because VM guests thatare installing VMware Tools will not migrate because the VMware Tools is not on a shared storage. You will get the error message “The virtual machine is installing VMware Tools and cannot initiate a migration operation”.

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {Dismount-Tools }

This last one finds all VM guests running Windows as guest OS and upgrades VMware Tools without a reboot at the end

Get-VM | Where {$_.PowerState -eq “PoweredOn” -and $_.Guest.OSFullName -match “Win*”} | % {Update-Tools -VM $_ -NoReboot}

VM Tools and Virtual Hardware Versions

Get-VM | Select Name, Version

But the returned object doesn’t have a root property for ToolsVersion or ToolsVersionStatus, for this we need to delve into the ExtensionData property and have a look around, once we have found the information it is fairly easy to add these to our object using the New-VIProperty cmdlet as below:

New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine `
-ValueFromExtensionProperty ‘Config.tools.ToolsVersion’ `
-Force

New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine `
-ValueFromExtensionProperty ‘Guest.ToolsVersionStatus’ `
-Force

Now we have added these as a new property to our object (actually they are PowerShell Code Properties), we can use our old friend Get-VM to retrieve the information easily:

Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

Of course we can choose which list of VMs to get this information for:

For a Datacenter: Get-Datacenter London | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

For a cluster: Get-Cluster Production | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

For a host: Get-VMHost Host1.mydomain.local | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus

And we can also easily export this information into a csv file:

Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus | Export-Csv -NoTypeInformation -UseCulture -Path C:\Temp\VMHWandToolsInfo.csv

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