Find vms with active vmware tools installation using PowerCLI.

by Grzegorz Kulikowski

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:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2083169
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:
[sourcecode language=”powershell”]
eject -v –cdrom /dev/cdrom
[/sourcecode]
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
[sourcecode language=”powershell”]
$affectedvms = get-view -viewtype virtualmachine -property ‘name’ -Filter @{‘Runtime.ToolsInstallerMounted’=’True’}
$affectedvms.count
11
[/sourcecode]
Ok, so i have 11 vms with mounted vmware tools installation iso. I will now unmount it in batch.
[sourcecode language=”powershell”]
foreach ($vm in $affectedvms) {$vm.UnmountToolsInstaller()}
[/sourcecode]
Ok, to be 100% sure, we have to check afterwards if everything went smooth or we hit the issues described in KB mentioned earlier.
[sourcecode language=”powershell”]
$affectedvms = get-view -viewtype virtualmachine -property ‘name’ -Filter @{‘Runtime.ToolsInstallerMounted’=’True’}
$affectedvms.count
2
[/sourcecode]
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.
vmt1

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

While running loops with UnmountToolsInstaller() method watch out for vms that will get into a ‘Question’.
[sourcecode language=”powershell”]
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
disconnecting.

Disconnect anyway and override the lock?
[/sourcecode]

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 😉
$creds=get-credential
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.

You may also like

Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish
Streaming live on Twitch right now.
CURRENTLY OFFLINE