Find vms with active vmware tools installation using PowerCLI.

Today i want to show you how to fix and find vms with active vmware tools installation (hanging/broken).
1) Locate all the vms with the issue
2) Fix // end vmware tools installation.

Step 2, should be normally easy. Just use option from VM context menu (Guest-> End VMware tools install). In case that it will not work you can follow the KB:
The KB says : “Ensure to not use SCSI eject”.
I had few vms that had this issue, the ‘End VMware tools install’ option went away actually after issuing:

eject -v --cdrom /dev/cdrom

Make sure you wait , 3-5 seconds after issuing this, and then check if the vmware tools install is done.
After issuing this command VM went back to normal state, and i could perform vmotions for those vms.

Step 1, for locating those vms with hanging vmware tools installation we can use get-view with proper filter

$affectedvms = get-view -viewtype virtualmachine -property 'name' -Filter @{'Runtime.ToolsInstallerMounted'='True'}

Ok, so i have 11 vms with mounted vmware tools installation iso. I will now unmount it in batch.

foreach ($vm in $affectedvms) {$vm.UnmountToolsInstaller()}

Ok, to be 100% sure, we have to check afterwards if everything went smooth or we hit the issues described in KB mentioned earlier.

$affectedvms = get-view -viewtype virtualmachine -property 'name' -Filter @{'Runtime.ToolsInstallerMounted'='True'}

It is now 2, so we have to manually now fixe 2 vms. Let’s do that now.

Let’s mount vmware tools iso for this VM that is in this case a linux vm.

After this mount the cd in /media for example, and type :
“eject -v –cdrom /dev/cdrom”
like on the screenshot

While running loops with UnmountToolsInstaller() method watch out for vms that will get into a ‘Question’.

PowerCLI C:\> $a |Get-VMQuestion

Text                                               Options              Default
----                                               -------              -------
msg.cdromdisconnect.locked:The guest operating     {Yes, No}            Yes
system has locked the CD-ROM door and is probably
using the CD-ROM, which can prevent the guest
from recognizing media changes. If possible,
eject the CD-ROM from inside the guest before

Disconnect anyway and override the lock?

Also i believe you need to have in your system ‘eject’ program. Even if i tried to reinstall vmware tools to get this fixed, it was unable to finish as it was reporting missing ‘eject’.
For windows boxes, like the KB says, shutdown the VM and check for connected isos.

This is also useful 😉
get-view -viewtype virtualmachine -property ‘name’ -Filter @{‘Runtime.ToolsInstallerMounted’=’True’} | %{Invoke-VMScript -VM $_.Name -ScriptText ‘eject -v –cdrom /dev/cdrom’ -ScriptType Bash -GuestCredential $cred}
It will try to pass the eject command to affected vms.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s