Jeremy Davis
Jeremy Davis
Sitecore, C# and web development
Article printed from:

Automating uninstalls of Sitecore

Published 01 June 2015
Updated 25 August 2016

Quick bit of script this week. Ages back I wrote up the process for working out how to run unattended installations of Sitecore using its .exe installer and then converted that to PowerShell. Recently I've been doing a bit more work on install automations in PowerShell. (Which I plan to write up in future posts) But while doing this, I realised that the flip side of automating the install is that it's also helpful to be able to remove an instance of Sitecore automatically too...

Following the same approach of using Process Explorer from my original post, you can spy on what the Sitecore Installer does when you try to remove an instance. What you'll find is that it's executing a command which looks a bit like this:

"msiexec.exe" /x "{54A31CFD-B937-5EE9-AE02-68171A616585}" /qf /l*v "C:\Users\jeremy\AppData\Local\Temp\2\SitecoreInstaller.log" 


Doing a bit of digging through the docs for msiexec.exe suggests that what's being passed here is:

  • /x: Is the flag to request uninstalling a specific package
  • The guid: Is the unique ID of the package from when it was installed
  • /qf: Requests the standard UI
  • /l*v: Means write a verbose log
  • Log file path: The absolute path to the log file to write for the uninstall process

So the key thing you need to work out to automate an uninstall is what the unique ID of your particular Sitecore install was. Fortunately PowerShell's integration with WMI can help here. The Get-WmiObject command can return this data for an installed program, so all that's necessary is to filter it correctly (by finding the right name) and extract the right entry.

A second minor change that you need to make is to swap the /qf flag that shows the full UI for the uninstallation with the /qn flag which will hide the user interface.

So a script to uninstall an instance could look like:


$msi = "msiexec.exe"

Write-Host "Finding package ID for $instanceName"
$instanceID = Get-WmiObject Win32_Product | where { $_.Name -like "*$instanceName" } | select -first 1

Write-host "Uninstalling $($instanceID.Name)"
&$msi /x "$($instanceID.IdentifyingNumber)" /qn /l*v "$($pwd)\Uninstall.log"

Write-Host "Done."


The script takes one parameter - the instance name which you installed Sitecore with originally. Then it uses WMI to find the first installation whose display name ends with the instance name supplied. (All Sitecore installs are named with this pattern) And finally it constructs the correct command line for msiexec.exe

So if you save your script to "RemoveInstance.ps1" and your instance is called "ExampleSite" you can run:

.\RemoveInstance.ps1 ExampleSite


And no more instance...

The script was written for the v6.6 installer, but I suspect it will work against most releases. There doesn't seem to be anything obviously version specific in the process of removing an instance.

↑ Back to top