0

QuickTip – PowerShell Unable To Run MSIEXEC Command Line

In this case there was an issue uninstalling the Azure Migrate Mobility Service, but the same principal will apply to running MSIEXEC commands in PowerShell that are not correctly formatted.  The Azure Migrate Mobility Service is a key component used during server replication to Azure. The Mobility Service agent is installed on machines to capture disk information and send it to the Azure Migrate appliance for ongoing synchronization. While it’s essential during migration or testing phases, it’s no longer needed once a machine has been fully migrated.  It can then be removed.  However when removing the Azure Migrate Mobility Service from a machine, there were some issues.

In this case, I wanted to removed the Mobility Service using command line as there were multiple machines involved and did not want to have to do this manually on every single server.

Uninstall Information

If we look in the standard registry location for uninstall information, we can see that the there is an uninstall command listed for the Mobility service.

As seen in the image below, this is under:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{275197FC-14FD-4560-A5EB-38217F80CBD1}

Mobility Service Uninstall Registry Information

If we look at the uninstall string in the registry, one thing should jump out at you.

MsiExec.exe /I{275197FC-14FD-4560-A5EB-38217F80CBD1}

Is that really the command line option to do the uninstall?  It's also the same as what is in the ModifyPath in the above screenshot.

For a giggle, let's just run the command as-is, as see what it does.  In the image below, the command was executed and then Programs and Features was opened.

Mobility Service Uninstall Command Did Nothing

Well that did nothing.  The Mobility Service is still listed.  Oh well.

Since that failed, we will make some modifications.  The important thing is that we have the package ID.

For reference, the full documentation on msiexec.exe can be viewed on Learn.

Command Prompt Uninstall Example

We have the package ID, so all we need to do is tweak the command to tell it to uninstall – that command line option  is /X and is shown below.

Depending upon your preference you may want to use the Passive or Quiet along with an option to force a restart.

MsiExec.exe /X {275197FC-14FD-4560-A5EB-38217F80CBD1} /Passive /ForceRestart
MsiExec.exe /X {2751EB-38217F80CBD1} /Quiet /ForceRestart

 

PowerShell Uninstall Example

Running the exact same command that worked in the cmd prompt, will fail in PowerShell as it is a different environment.  The exact same command is shown the image below.  Note that all that it does is to unexpectedly bring up the  MSI help information.  More importantly, the uninstall does not work.  That means you either have a typo or are running the command in PowerShell.  In our case we know the command was good and it ran in the cmd prompt.  What is up with PowerShell?

If you try the cmd prompt syntax in PowerShell you will typically see this:

PowerShell Command Fails With Unexpected MSIEXEC Help File

The quick fix is to use a cmd prompt as the above syntax is for cmd prompt. Move on, not the droids you are looking for...

If you really want to fix it, you need to escape the characters that PowerShell is not happy about.  The same character escape issue happens if you specify a path to the MSI and the path has a space or special character.  It needs to be escaped.

In PowerShell the escape character is `  which is the grave-accent.

A PowerShell sample command with the necessary escape characters present would be:

MsiExec.exe /X`{275197FC-14FD-4560-A5EB-38217F80CBD1`} /Passive  /ForceRestart

Correctly Escaped MSIEXEC PowerShell Command Now Works

Now that the command has been correctly formatted for PowerShell, the uninstall process is initiated.

Cheers,
Rhoderick

Rhoderick Milne [MSFT]

Leave a Reply

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