Cleanly Uninstalling Stubborn SQL Server Components
Problem
There are scenarios where SQL Server is difficult or impossible to uninstall, upgrade, or replace (and these can block you from installing a new version or using a specific named or default instance):- An expired Evaluation Edition:
Evaluation period has expired. For information on how to upgrade your evaluation software please go to http://www.microsoft.com/sql/howtobuy
- An expired Management Studio:
Your Microsoft SQL Server Management Studio evaluation period has expired.
You can get a key to extend your trial by registering this copy of Microsoft Management Studio online. You may also purchase a key to activate the product. - Unsupported operating system (after an OS upgrade):
The operating system on this computer does not meet the minimum requirements for SQL Server xxxx.
- Missing MSI files, e.g.:
Slp: Target package: "C:\...\sql_engine_core_inst.msi"
Slp: InstallPackage: MsiInstallProduct returned the result code 2. - Too many instances to remove individually, or other various errors during uninstall.
Solution
There is a built-in command calledmsiexec
which has an
uninstall parameter (-x
). This command can be used to remove
stubborn programs through brute force. First, though, you need to get an
inventory of the GUIDs that represent the programs you need to remove. All you
see in the Control Panel are the friendly names, as you can see here:
msiexec
and the GUIDs for the products.)You can get the GUID associated with each installed product by searching around the registry, but I would rather use the MSI Inventory tool, which you can download (
msiinv_new.zip
) from
this OneDrive folder, and extract msiinv.exe
to a folder, say
C:\temp\
.Once that file is there, you can open a PowerShell console, and run the following code:
c:\temp\msiinv.exe -s | Select-String "SQL Server" -Context 0,1

msiexec
, but ultimately where I want
to end up is a set of commands I can run directly from the command line, for
example:rem Microsoft SQL Server System CLR Types msiexec /x "{C3F6F200-6D7B-4879-B9EE-700C0CE1FCDA}" rem SQL Server 2014 Integration Services msiexec /x "{327B1B40-2434-4DC5-9D4D-B9B24D4B2EDE}" rem SQL Server 2014 SQL Data Quality Common msiexec /x "{2D95D8C0-0DC4-44A6-A729-1E2388D2C03E}" ...
$a = c:\temp\msiinv.exe -s | Select–String "SQL Server" -Context 1,1; $a = $a -replace "Product code: ","msiexec /x """; $a = $a -replace ">", "rem"; $a = $a -replace "\t", ""; $a = $a -replace "}","}"""; $a | Out-File c:\temp\remove.bat -encoding ascii;
remove.bat
, look through the list, and
remove any products you *don't* want to uninstall. The format will look like
this, almost exactly how I wanted them:rem Microsoft SQL Server System CLR Types msiexec /x "{C3F6F200-6D7B-4879-B9EE-700C0CE1FCDA}" rem SQL Server 2014 Integration Services msiexec /x "{327B1B40-2434-4DC5-9D4D-B9B24D4B2EDE}" rem SQL Server 2014 SQL Data Quality Common msiexec /x "{2D95D8C0-0DC4-44A6-A729-1E2388D2C03E}" ...

msiexec
, like /quiet
. You can enable
/quiet
by changing the second last line in the Powershell script above
to:$a = $a -replace "}","}"" /quiet";
/quiet
, you will see multiple notifications that the
product you're trying to remove is no longer installed:

Select-String
. I wanted to focus on a single
run-through with the SQL Server components, since they are the ones that prove
most problematic.
Comments
Post a Comment