Uninstall VMware Tools with Powershell

In addition to this great post by MigrationMark about Automating VM Migration and uninstalling VMware Tools I decided to write a little powershell script that finds the GUID of the VMware Tools Registry Key and use it to uninstall VMware Tools with this key.

This powershell script will uninstall VMware Tools and force shutdown the server in 120 seconds.
Note: Backup your VM before doing this!

$regpath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\uninstall"
Get-childItem $regpath | %  {
$keypath = $_.pschildname
$key = Get-Itemproperty $regpath\$keypath
if ($key.DisplayName -match "VMware Tools") {
$VMwareToolsGUID = $keypath
}
MsiExec.exe /x $VMwareToolsGUID  /qn /norestart
shutdown -s -t 120 -f
}

7 thoughts to “Uninstall VMware Tools with Powershell”

  1. Hi Darryl.

    I can’t seem to get your script to work. The $keypath variable ($_.pschildname) is not a GUID as far as I can tell.

    This is the result I get for $keypath when I run this in a W2k8 server (a Hyper-V VM so no VMware Tools installed but I should still get a GUID IMO).

    PS C:\Scripts> .\uninstall_vmt.ps1
    AddressBook
    Connection Manager
    DirectDrawEx
    Fontcore
    IE40
    IE4Data
    IE5BAKEX
    IEData
    MobileOptionPack
    SchedulingAgent
    WIC

    Any thoughts?

    1. Hi Martin,

      You won’t get a GUID if no VMware Tools installed.
      The script matches the key “Displayname” with valuedata “VMware Tools”, if there is no VMware Tools installed this key doesn’t exists.

      VMware tools always uses the GUID as Registry Key Path name. So the $keypath is the GUID.
      In the registry under the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\VMWAREGUID there is also a key called “UninstallString” where the same GUID is used.
      Because I use extra parameters “/qn /norestart” in the scripts I didn’t want to use this key.

      1. Ah, I understand.

        The reason I asked is because I got a question from a colleague on how to uninstall the Hyper-V Integration Components and figured that all applications had a GUID I could use for uninstalling.

        Am I correct if I assume that I can still use the $keypath variable for uninstalling the Integration Components?

        1. The Intergation services is a different proces, the above script is only for VMware Tools.

          Found the solution your searching for here;
          http://social.technet.microsoft.com/Forums/en-US/winserverhyperv/thread/c3007a9a-a6aa-406a-b259-af11ca171be6/

          1. Start the Hyper-V management console
          2. Start and Connect to your Virtual Machine
          3. Click on Action > Insert Integration Services Setup Disk
          4. Log onto your virtual machine and open the command prompt
          5. At the command prompt browse to the Integration Services Setup Disk(D:\ in most cases)
          6. At the command prompt browse to D:\support\amd64 or D:\support\x86 depending on the arch of the vm
          7. To Uninstall the Integration Services, just type in the command prompt >Setup.exe /uninstall
          8. Restart the VM to make sure that the uninstallation process worked

          1. Uninstalling Integration Services manually is not a problem.

            I was looking for a way to do it with Powershell, like what you have done with your script but for VMware Tools.

  2. There is no way to uninstall the Intergration Services without the Integration Services Setup Disk.
    Unlike VMware Tools the Intergration Services is a set of windows services based on svchost.exe

    1. Ok, I didn’t know that you needed the setup disk but that changes everything.

      Thanks for the feedback, much appreciated. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *