Cleanly Uninstalling Stubborn SQL Server Components

By:   |   Comments (65)   |   Related: > Install and Uninstall


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):

  1. 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

  2. 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.

  3. Unsupported operating system (after an OS upgrade):
    The operating system on this computer does not meet the minimum requirements for SQL Server xxxx.


  4. Missing MSI files, e.g.:
    Slp: Target package: "C:\...\sql_engine_core_inst.msi"
    Slp: InstallPackage: MsiInstallProduct returned the result code 2.

  5. Too many instances to remove individually, or other various errors during uninstall.

In these situations, is there a way to cleanly uninstall SQL Server?

Solution

There is a built-in command called msiexec 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:

Control Panel : Before

(This is a brand new system where I installed multiple SQL Server 2014 components in order to demonstrate my approach of cleanly removing them without using the Control Panel or SQL Server's own setup, but rather using 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

Here is a truncated version of what my output from that command looks like (there is a benign error you can ignore):

Powershell command output

This output is marginally useful for now; I can quickly scan the list and see all the GUID codes for the products I want to remove, and start mentally filtering any out as necessary. I could manually copy and change the output to feed each GUID individually to 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}"
  
...

And I get there with a little help from my good buddy, co-worker, and PowerShell officionado, Allen White (@SQLRunr):

$a = c:\temp\msiinv.exe -s | Select-String "SQL Server" -Context 1,1;
$a = $a -replace "Product code:","msiexec /x """;
$a = $a -replace "Language:","rem Language:";
$a = $a -replace "Package:","rem Package:";
$a = $a -replace ">", "rem";
$a = $a -replace "\t", "";
$a = $a -replace "}","}""";
$a | Out-File c:\temp\remove.bat -encoding ascii;

Now, you can open up 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}"

...

Now run remove.bat from the command line. You'll get prompts like this:

Windows Installer prompts

And you'll also likely see some confirmation dialogs from User Account Control. You may get some errors or dependency warnings, and to avoid some of the prompts, you'll want to make sure all related services have been manually stopped. You might want to run from an elevated command prompt (perhaps even using the "super admin" if you're on Windows 10), and also play with some of the switches to msiexec, like /quiet. You can enable /quiet by changing the second last line in the Powershell script above to:

$a = $a -replace "}","}"" /quiet";

Also, you may have to run the script twice to completely remove things that failed the first time due to dependency order. The second time around, if you don't use /quiet, you will see multiple notifications that the product you're trying to remove is no longer installed:

You can only remove a product once

But after running through it twice, this should leave you with a much cleaner Control Panel:

Control Panel : After

The remainder of these items should really be much easier to remove manually; or, you may not want to bother; or, you could repeat the process above with different arguments to 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.

Summary

This is not the most intuitive approach in the world, but I hope it helps some of you remove stubborn, sticky SQL Server components from your systems. It constitutes a bit more work than normal uninstall operations, but when Control Panel or SQL Server Setup won't cooperate, this might be the next best thing. (Note that this procedure will not be effective in completely removing a clustered instance of SQL Server; I wouldn't even try.)

Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Aaron Bertrand Aaron Bertrand (@AaronBertrand) is a passionate technologist with industry experience dating back to Classic ASP and SQL Server 6.5. He is editor-in-chief of the performance-related blog, SQLPerformance.com, and also blogs at sqlblog.org.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Monday, September 23, 2024 - 5:43:00 PM - Brett McDonald Back To Top (92527)
Thanks man, I tried everything to fix a bad SQL Misinstall. This worked!

Tuesday, March 12, 2024 - 10:10:13 AM - WMiller Back To Top (92062)
Thank you for this, it worked like a charm and provided an alternative to the uninstall and manual registry scrubbing I had been doing.

Friday, January 19, 2024 - 10:05:14 AM - Paul Catana Back To Top (91865)
Thank you sir and your friend Allen White !!!
I had this problem for hours and hours
Worked like magic

Wednesday, August 9, 2023 - 7:19:44 PM - Hector Serrano Back To Top (91478)
Tks a lot!

Thursday, June 15, 2023 - 4:00:37 PM - Steve Back To Top (91302)
This worked when nothing else would! Thank you so much!!

Friday, November 4, 2022 - 6:27:37 PM - Jiri Back To Top (90664)
Magic! Thank you much.

Friday, January 14, 2022 - 7:43:15 AM - maksim kholin Back To Top (89661)
Thanks for your help.
I fixed with your help.

Thursday, December 9, 2021 - 6:20:39 AM - Josué Ando Back To Top (89557)
Thank you very much for that answer. You saved my life!

Friday, November 12, 2021 - 8:11:32 AM - santhosh Back To Top (89437)
Thank you, sir. This really helped us.

Thursday, October 28, 2021 - 1:15:16 AM - Srujana Back To Top (89373)
Many Thanks for this , it helped me a lot.

Thursday, July 1, 2021 - 11:43:40 AM - Philippe ALBERT Back To Top (88933)
Hello and many thanks for this solution.
I am trying to uninstall SQL Server 2014 from approx. 400 computers in my company.
I would like to make it as simple, as automatic and as quiet as possible for the users. I can't see them click on OK , ignore or else every 2s for 5 min...
Yet, when I use the /quiet switch, nothing uninstalls.
Any idea what I am doing wrong ?

Friday, June 4, 2021 - 9:17:57 AM - Aaron Bertrand Back To Top (88799)
ashima, I'm pretty sure error 1605 is ok; it just means you tried to uninstall the same application more than once. If you run the powershell to generate the batch file again, and run it again, keep doing that until the batch file is empty.

https://help.pdq.com/hc/en-us/articles/220509207-Uninstalling-Application-Returns-Error-1605

Friday, June 4, 2021 - 3:12:53 AM - ashima Back To Top (88797)
I am trying this solution but after i try this:-
$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;

getting this error:
unexpected error 1605()

please help...

Thursday, May 20, 2021 - 4:05:44 PM - Paul Johnson Back To Top (88721)
Dude...cannot tell you how much this helped. That stupid Polybase reg key was kicking my tail. I used your msiexec magic here and the rest of SQL Server uninstalled like a hot knife in butter. Great post. Thanks!

Monday, August 31, 2020 - 12:40:06 PM - Daniel Back To Top (86395)
Many thanks

Monday, August 31, 2020 - 12:38:50 PM - Daniel Back To Top (86394)
had the same problems with the select-string error and I found the error, there is one little mistake in the script.

Solution
Make sure your substituted folder name is small letters all through

Thursday, May 14, 2020 - 12:49:21 PM - Pablo Echeverria Back To Top (85659)

I can't thank you enough for the many times this post has saved me! Always struggling in one way or another with stubborn Micros!@# components!


Monday, February 24, 2020 - 11:20:35 PM - Zach H. Back To Top (84781)

This webpage has officially saved my sanity!!  I have been through two weeks of failed installs and uninstalls of just about every version of SQL Server.  Nothing would stick.  I would keep getting some kind of "SQL Server Browser" error.  I even hand-searched and deleted 'SQL Server' keys out of the Registry (don't do this).  Nothing worked.

I ran everything in this post, rebooted, and with the first try, I got SQL 2017 installed!

I can't thank you enough for this information.  I would have never thought about using Power Shell.


Tuesday, October 15, 2019 - 9:35:57 PM - Garric Back To Top (82790)

To remove SQL can help following lines of bat file:

start "" "J:\Setup.exe" /Action=Uninstall /FEATURES=SQL,AS,RS,IS,Tools,SQLENGINE,REPLICATION,FULLTEXT,CONN,IS,BC,SDK,BOL /INSTANCENAME=SQL2014 

start "" "J:\Setup.exe" /Action=Uninstall /FEATURES=SQL,AS,RS,IS,Tools,SQLENGINE,REPLICATION,FULLTEXT,CONN,IS,BC,SDK,BOL,BIDS,OCS /INSTANCENAME=SQL2008 


Tuesday, October 15, 2019 - 9:21:01 PM - Garric Back To Top (82789)

It is better when all the files are in the same folder. This code will write remove.bat.txt to the same folder and run msiinv.exe, which is located in the same folder. Added txt extension for editing and preventing accidental launch. It would be nice if you could add a search directly in the window of the executing bat file.

Start.bat:

powershell -noexit "& "".\RemoveByGuid.ps1"""

RemoveByGuid.ps1:

$path = $MyInvocation.MyCommand.Path | split-path -parent 

$exe = Join-Path $path -childpath "msiinv.exe"

$Parms = "-s"

$a = & $exe $Parms | 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 "}","}""";

$path = Join-Path $path -childPath "remove.bat.txt" 

$a | Out-File "$path" -encoding ascii;


Friday, June 28, 2019 - 10:38:20 AM - Robert Gowdey Back To Top (81627)

@Tony Ownes

Perfection! Thank you!


Saturday, June 22, 2019 - 10:21:55 PM - JHebert Back To Top (81556)

Life saver. Thank you for your time and effort in writing this blog and helping many!


Wednesday, June 12, 2019 - 9:45:59 AM - Aaron Bertrand Back To Top (81433)

Don, see the comment from Christoph below, you can try without the semi-colon on the first line.


Wednesday, June 12, 2019 - 12:41:12 AM - Don Haque Back To Top (81425)

PS C:\> $a = c:\GUtemp\msiinv_new\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:\GUtemp\remove.bat -encoding ascii;
Select–String : The term 'Select–String' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:43
+ $a = c:\GUtemp\msiinv_new\msiinv.exe -s | Select–String "SQL Server"  ...
+                                           ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Select–String:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Saturday, April 27, 2019 - 12:17:29 PM - Raphael NazirUllah Back To Top (79778)

I installed SQL Server 2017 and started it.

After it started running, I began installation of SSMS 18 GA. However, due to some reason, the SSMS installation got stuck at the same progress. So I killed the SSMS installation "task" from the Task Manager, and restarted my PC.

Now I can neither install nor uninstall SSMS 18 from any normal means. The SSMS setup shows error : "Setup has been blocked". SSMS 18 lists as being installed in Control Panel, but I cannot uninstall it.

I tried the given approach for it, but the following occurs on my console:

PS C:\Temp> .\msiinv.exe -s |Select-String "Management Studio" -Context 0,1;
Unexpected error: 1605 ()
Unexpected error: 1605 ()
Unexpected error: 1605 ()

The same occurs for any search in string.

Have no idea what to do.


Thursday, December 27, 2018 - 2:06:49 PM - Tony Owens Back To Top (78569)

 You can do all of this directly from PowerShell without needing any addditonal extensions, and with only a few lines.

$SQLVersion = "SQL Server 2017"
$Applications = Get-WmiObject Win32_Product | Select Name,IndentifyingNumber | ? {$_.Name -like "*$SQLVersion*"}
foreach ($Application in $Applications)
{
    msiexec.exe /x $Application.IdentifyingNumber /quiet
}


Thursday, December 27, 2018 - 5:10:28 AM - Baron Back To Top (78564)

Thanks for this article. I will try your ideas since I'm having a hard time reinstalling sal server after the expiration of my trial version.


Friday, November 30, 2018 - 11:28:57 AM - David Back To Top (78375)

Nice code, thanks for sharing.

Added a set location to only have one place to change the location

Also added a line to comment out the lines with "Package"

set-location C:\temp

$a = .\msiinv.exe -s | Select-String "SQL Server" -Context 1,1;

$a = $a -replace 'Product code: ','msiexec /x "';

$a = $a -replace '>', 'rem';

$a = $a -replace 'Package:', 'rem Package:';

$a = $a -replace '\t', '';

#$a = $a -replace '}','}"';

$a = $a -replace '}','}" /quiet';

$a += 'rem Ref:https://www.mssqltips.com/sqlservertip/4050/cleanly-uninstalling-stubborn-sql-server-components/'

$a | Out-File .\removeSQLinstall.bat -encoding ascii;


Wednesday, May 23, 2018 - 11:58:08 AM - Joe Back To Top (76011)

Really useful,

Tks Aaron. JK 

 


Wednesday, February 28, 2018 - 3:42:15 PM - Hiram Back To Top (75323)

Edited script to successfully generate the Remove.bat on Win2016.

 

$a = c:\temp\msiinv.exe -s | Select-String "SQL Server" -Context 0,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;

 


Friday, February 9, 2018 - 1:59:31 PM - VirtualJingo Back To Top (75164)

 This really helped me out so I though I would share the changes I made.  This will run this install locally or on a remote host.  Also I am looking to switch to WMIC so there isn't a need to copy a file.

Thanks for this article!

 

#requires -version 4

<#

.SYNOPSIS

Props:

  https://www.mssqltips.com/sqlservertip/4050/cleanly-uninstalling-stubborn-sql-server-components/

 

Cleanly Uninstalling Stubborn SQL Server Components

 

.DESCRIPTION

  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)

 

There is a built-in command called msiexec 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.

 

Important!!!!

Keep the msiinv.exe file in the same folder as this script.

 

.PARAMETER WorkingDir

  Sets the directory where this script and the msiinv.exe file are located.

.PARAMETER Computers

  Set a list of Computers that you want to uninstall software e.g. "Computer1", "Computer2"

.PARAMETER Software

  Set which software you want to uninstall e.g. "SQL Server"

  If you need to see what is installed; user msiinv.exe in a powershell windows by running:

  .\msiinv.exe -p

.PARAMETER Credentials

  Credentials to be used to run this script; needs to be local admin of each machine.

.INPUTS

  msiinv.exe pulls info about installed SQL components.

.OUTPUTS

  remove.bat is created from this script and then is ran to uninstall all

  software components on a server.

.NOTES

  Version:        2.0

  Original Author:         Aaron Bertrand

  Contributing Author:      VirtualJingo

  Creation Date:  2015-10-06 

  Last Updated: 2018-02-08

  Purpose/Change: Initial script development

.EXAMPLE

  Set each parameter and then run the script.

#>

 

$Workingdir = "c:\temp"

$Computers = "localhost"

$Software = "SQL Server"

$Credential = $Host.ui.PromptForCredential("Need credentials", "Please enter your user name and password.", "", "NetBiosUserName")

 

ForEach ($Computer in $Computers) 

{

 

    If ($Computer -like '*localhost*')

        {

        Write-host "Uninstalling on localhost...Please standby."

        Write-host "Collecting installed software"

                $a = .$Workingdir\msiinv.exe -s | Select-String $Software -Context 1,1;

                $a = $a -replace "Product code: ","msiexec /x """;

                $a = $a -replace ">", "rem";

                $a = $a -replace "\t", "";

                $a = $a -replace "}","}"" /quiet";

                $a | Out-File $Workingdir\remove.bat -encoding ascii;

                Write-host "Starting first pass"

                Start-Process -FilePath $Workingdir\remove.bat -verb runas

                Write-host "Starting second pass"

                Start-Process -FilePath $Workingdir\remove.bat -verb runas

                Write-host "Your selected Product should now be untinstalled; please verify."

        }

    

    elseif ($Computer -notlike '*localhost') 

        {

            

            Write-host "Uninstalling on remote host $Computer...Please standby."

            New-PSDrive -Name Y -PSProvider FileSystem -Root \\$Computer\C$\temp -Credential $VMDomainCredential -Persist

 

            $source =  "$WorkingDir\msiinv.exe"

            $destination = 'y:\msiinv.exe'

    

            $TestPath = Test-Path $destination

            IF (!$TestPath)

                {Copy-Item $source $destination -Verbose}

            ELSE

                {

            IF (((Get-ChildItem $source).Length -ne (Get-ChildItem $destination).Length) -or ((Get-ChildItem $source).LastWriteTime -ne (Get-ChildItem $destination).LastWriteTime))

                {Copy-Item $source $destination -Force -Verbose}

            ELSE

            {'Exact file found, nothing copied'}

            }

            

            Invoke-Command -ComputerName $Computer -Credential $Credential -ScriptBlock {

                param($Software)

                Write-host "Collecting installed software"

                $a = c:\util\msiinv.exe -s | Select-String $Software -Context 1,1;

                $a = $a -replace "Product code: ","msiexec /x """;

                $a = $a -replace ">", "rem";

                $a = $a -replace "\t", "";

                $a = $a -replace "}","}"" /quiet";

                $a | Out-File C:\util\remove.bat -encoding ascii;

                Write-host "Starting first pass"

                Start-Process -FilePath c:\util\remove.bat -verb runas

                Write-host "Starting second pass"

                Start-Process -FilePath c:\util\remove.bat -verb runas

                Write-host "Your selected Product should now be untinstalled; please verify."

                }  -ArgumentList $Software

            Remove-PSDrive -name y

        

        }

    else 

        {

            Write-host "Something went wrong...goodbye."

            Exit

        }

 

}

 


Tuesday, February 6, 2018 - 9:48:45 PM - Hoàng Back To Top (75122)

 

how do you get to c:/temp cmd ? I can only access to cmd system? 


Tuesday, February 6, 2018 - 9:42:54 PM - Hoàng Back To Top (75121)

"0:Watson 1:1807 2:StreamSupportFiles 3:getBootStrapDirectory 4:3 5:e:\sql12_main_t\sql\setup\darwin\sqlcastub\catarget.cpp 6:138 7:sqlcastub.dll 8:sqlrun.msi"
I want to delete SQL server but it is far more subborn than just using (msiexec /x "{}") and one of them I think are the issue. Here's the powershell code.
---

> SQL Server 2014 Database Engine Services

        Product code:   {C8511A82-E9FD-4B6D-B1B2-378589D2B48A}

> SQL Server 2014 Database Engine Services

        Product code:   {5082A9F3-AEE5-4639-9BA7-C19661BA7331}

> SQL Server 2014 Common Files

        Product code:   {F7012F84-80F5-4C25-852E-B1BA03276FE6}

> SQL Server 2014 Database Engine Services

        Product code:   {0E4525B4-8B3D-429D-A283-2D6F9583EC5A}

> SQL Server 2014 Database Engine Services

        Product code:   {D45C3EC4-282E-4798-98C7-E7BF2362F04E}

> SQL Server 2014 Management Studio

        Product code:   {75A54138-3B98-4705-92E4-F619825B121F}

> SQL Server 2014 Database Engine Shared

        Product code:   {ACC530B8-B6B4-40D6-B59B-152468CF47D0}

> SQL Server 2014 Database Engine Services

        Product code:   {8B9312D8-1BDB-4A44-A52F-4AB73BD300FD}

> SQL Server 2014 Database Engine Shared

        Product code:   {D1B847A9-B06B-4264-9EF0-78E6E1571E65}

> SQL Server 2014 Management Studio

        Product code:   {839EF29A-3055-43DC-ADCE-8E84893798D5}

> SQL Server 2014 Client Tools

        Product code:   {2BA1811B-44C0-4C50-8C5A-CE68AB25ED71}

> SQL Server 2014 Common Files

        Product code:   {BD1CD96B-FE4B-4EAE-83D4-6EF55AB5779C}

> SQL Server 2014 Client Tools

        Product code:   {B5ECFA5C-AC4F-45A4-A12E-A76ABDD9CCBA}

 

> Microsoft SQL Server 2014 Setup (English)

Product code:   {37C44B5C-E839-4A9D-9E20-A93E1B2FD35A}

>       Installed from: C:\Program Files\Microsoft SQL Server\120\Setup Bootstrap\Update Cache\KB3045324\GDR\1033_ENU_LP\x64\setup\sqlsupport_msi\

Package:    sqlsupport.msi

 

> SQL Server 2014 Database Engine Services

        Product code:   {17531BCD-C627-46A2-9F1E-7CC920E0E94A}

---
The Microsoft SQL Server 2014 Setup (English) is the main target here I think... It couldn't be delete with out deleting the coponent 1st :(


Monday, February 5, 2018 - 11:47:48 AM - Mohamed Bahaa Back To Top (75104)

 Thank you for your post , it's really help me it's remove most of them but i got error in some "sql failed to remove instance name"

an you help

 


Sunday, February 4, 2018 - 8:38:52 AM - Nesa Back To Top (75097)

Thanx a bunch, kind sir.
Cleared an unclearable situation.
Still some heroes out there.


Wednesday, January 24, 2018 - 3:40:44 PM - Dave Back To Top (75034)

 

This tip worked when nothing else would. This is a great utility to know about - msiexec.

Thanks for sharing!


Saturday, December 23, 2017 - 12:41:47 AM - Gabriel Navarrete Back To Top (74360)

Perfect works fine for me with SQL Server 2016 dev edition. I just had to go through all comments to fix problems with PowerShell and modify last second line as explained at the bottom of the article. Great job. 


Monday, October 30, 2017 - 1:22:30 PM - Aaron Bertrand Back To Top (68974)

Emily, you're running that from Powershell? Try from a standard command prompt.

Or, try the Powershell command Tibor Nagy posted at the very bottom of this page.


Monday, October 30, 2017 - 11:10:41 AM - Emily Back To Top (68968)

 

OS: Win10 64-bit.

 

 PS C:\Users\Emily Wagner> c:\msiinv\msiinv.exe -s | Select-String "SQL Server" -Context 0,1

Program 'msiinv.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1

+ c:\msiinv\msiinv.exe -s | Select-String "SQL Server" -Context 0,1

+ ~~~~~~~~~~~~~~~~~~~~~~~.

At line:1 char:1

+ c:\msiinv\msiinv.exe -s | Select-String "SQL Server" -Context 0,1

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException

    + FullyQualifiedErrorId : NativeCommandFailed


Monday, October 23, 2017 - 5:56:34 AM - Tan Pham Back To Top (68689)

Very helpful! Thank for your post 

 


Sunday, October 22, 2017 - 2:31:29 AM - Steve Kay Back To Top (68646)

Thanks!  You're a life-saver!


Sunday, August 13, 2017 - 9:22:33 PM - Fabio Fernandes Back To Top (64803)

Thanks a lot for this EXCELLENT piece of technical knowledge, Mr. Bertrand.

I just wanted to let you know that this is absolutely up-to-date: I was struggling with an SQL Server 2017 installation that failed during the first setup, a few hours ago, and was getting crazy trying to fix it. As you wrote, it "stucked" in a strange state where Control Panel and SQL Server Setup can´t cooperate...

Thanks to a tip from "andrey-wd" user at stackoverflow, pointing to this great solution, now it´s working fine (after a re-installation, of course).

You rocks, man!

 


Wednesday, May 31, 2017 - 12:44:48 PM - Alexandru Agrapine Back To Top (56358)

 You've saved my life. I was getting quite fustrating with this :D

 

Thank you.

 


Saturday, April 29, 2017 - 5:49:48 AM - Fawad Raza Back To Top (55294)

 

Thank you :) Saved me a lot of time.


Friday, April 28, 2017 - 9:01:03 AM - Steve Thorn Back To Top (55278)

Lifesaver, indeed. Was able to cleanly remove an otherwise botched SQL Server 2008/2012/2014/2016 removal.


Friday, April 28, 2017 - 3:47:50 AM - Martin Goodrich Back To Top (55264)

 Thank you so much for sharing this with the community. For me it has proved to be a lifesaver.

 


Wednesday, April 26, 2017 - 8:32:10 AM - Adrian Strangfeld Back To Top (55206)

Actually, how did you found out about  msiexec?

 


Wednesday, April 26, 2017 - 8:22:31 AM - Adrian Strangfeld Back To Top (55205)

This saved my day, thank you.

 


Tuesday, April 18, 2017 - 5:31:46 PM - Stephen Back To Top (55020)

 Just wanted to say thanks so much for this process.  I'm learning powershell and working on automating our customer server setup and this is really great stuff.  Thanks for taking the time to share this with all of us.

 


Thursday, March 30, 2017 - 9:30:21 AM - Raznor Back To Top (53951)

This is pure genius.


Wednesday, March 22, 2017 - 8:01:23 AM - Niki Back To Top (51530)

Worked perfect. Thanks.

But how do I get rid of the installed SQL updates ?

You find them under "Programs and Features" -> "Installed Updates"

 


Tuesday, March 7, 2017 - 2:31:21 PM - Zvonimir Back To Top (47517)

 

 Thank you, worked flawless with MSSQL 2016.


Tuesday, February 21, 2017 - 2:48:31 AM - Bala Krishna Back To Top (46539)

Hi  Aaron

Thank you for this, this worked for me

 

Regards

 

 


Monday, November 7, 2016 - 11:03:59 AM - Marc Back To Top (43712)

 Hi Aaron,

I have been trying to use your blog post info to remove a number of failed SQL Server installs. I just tried your MSI inv tool and received an unusual response in power shell, I am guessing there are some values missing in the reg key...

 

      Microsoft SQL Server System CLR Types (x64)
           Product code:    Server System CLR Types (x64)
       Unexpected error: 1605 ()

Do you have any guidance for handling this result?

 

thanks

 


Friday, October 14, 2016 - 12:37:06 PM - Julian Back To Top (43565)

Thank you Aaron. Very helpful.

Cheers,

Julian 

 

 


Sunday, September 11, 2016 - 10:42:05 PM - John D (JJDemps) Back To Top (43300)

Aaron,

 

This blog post was awesome!!!  You saved me so much time.  I was having issues with SQL Server 2016 not uninstalling gracefully because it ran into an issue uninstalling R.  So, then the whole uninstall process got messed up with older versions of SQL and Shared components.  These steps allowed me to remove all of the left over installer msi files from the various version components.

 

One thing I would like to note though.  It seems the blog post area for some of the Powershell scripts may have caused an encoding issue with the "-" character.  The line of code is "$a = c:\temp\msiinv.exe -s | Select-String "SQL Server" -Context 0,1" in the Allen White code block section. This appears to lead to the "Select–String : The term 'Select–String' is not recognized as the name..." error some people have been posting in the comments section.  I was pulling my hair out for about a half hour trying to figure it out.  My initial thought it was a non-printable character issue somewhere, because when I retyped the "Select-String" command the script worked.  But, when I repasted the code and just changed the spaces around the "Select-String" it still didn't work.  When I changed only the "-" in "Select-String" it worked again.  I pasted the line in Notepad++ and used the ASCII -> HEX Converter plugin, the "-" = E28093 in HEX. I pasted line in again retyping "-" over the pasted one in "Select-String", the "-" = 2D in HEX which is the correct HEX value for that character. 

 

So for anyone getting the "Select-String not recognized" error, try retyping the "-" in the code line "$a = c:\temp\msiinv.exe -s | Select-String "SQL Server" -Context 0,1" if you copy and paste the code into the Powershell window or Powershell ISE.

 

Thanks again Aaron. I have bookmarked this for future reference.

 

-John


Friday, September 9, 2016 - 4:42:25 PM - Jason Back To Top (43292)

 Receiving this error in Step 2:

PS C:\Windows\system32> The term 'Select-String' is not recognized as the name
The term 'The' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:4
+ The <<<<  term 'Select-String' is not recognized as the name
    + CategoryInfo          : ObjectNotFound: (The:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Friday, August 12, 2016 - 11:30:37 AM - Josh Back To Top (43113)

 Just a quick question. When running this part.

 

$a = $a -replace "Product code:    ","msiexec /x """;
$a = $a -replace ">", "rem";
$a = $a -replace "\t", "";
$a = $a -replace "}","}""";

 

The .bat doesn't seem to be replacing any of the text. I need to go into the bat file and manually "Replace all" to get it to format correctly. Is there something i could be doing wrong?

 


Thursday, July 21, 2016 - 7:15:38 PM - Ayotunde Sodipe Back To Top (41945)

 

 

Aaron,

 

Thank you very much for your guide on "Cleanly Uninstalling Stubborn SQL Server Components" guide.

 

Recently, I installed SQL Server 2016 Express and it worked perfectly well on the day I installed it and I was able to do every database assignment I wanted to do.  The following day, I started the bank charges software (Banker) connected to the SQL Server Express but was unable to connect to the database.  I tried so many guides to resolve the problem but could not.  Then I decided to uninstall the SQL Server 2016 Express but the uninstall failed because some components were unremovable.  Then, I decided to re-install the SQL Server 2016 Express with the hope that the new installation would overwrite the files of the unremovable components but the re-installation failed because of the unremovable components.  As a result, I started searching google for guides on how to remove the stubborn/unremovable components and I came across many guides but all the ones I got before coming across your guide were cumbersome, difficult-to-implement, ineffective and failed.  When I applied your guide, the stubborn components were removed successfully.

 

Henceforth, I will recommend your guide to anyone having any stubborn SQL Server components.

 

Thank you very much again and God bless you.

 

Yours,

 

Ayotunde Sodipe.

 


Tuesday, November 17, 2015 - 4:43:32 PM - Aaron Bertrand Back To Top (39090)

Thanks Cristoph, but why can a statement terminator be used on every line but that one?


Tuesday, November 17, 2015 - 2:56:26 PM - Christoph Back To Top (39088)

I had the same problems with the select-string error and I found the error, there is one little mistake in the script.

Remove the first semicolon in the first line and then you can run it from ISE.

$a=c:\temp\msiinv.exe -s | Select-String "SQL Server" -Context 0,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;

 


Thursday, October 8, 2015 - 8:42:35 AM - Peter Back To Top (38843)

I'm running Windows 8.1 and trying through the ISE, though pasting the same line in the command line below gives the same error. I can run just a Select-String without an issue, but piping to it is giving me fits for some reason.


Wednesday, October 7, 2015 - 6:29:57 PM - Aaron Bertrand Back To Top (38839)

Peter, what version of Windows, and where are you running the command (e.g. ISE vs. PS command line)?


Wednesday, October 7, 2015 - 5:13:30 PM - Peter Back To Top (38838)

Just can't seem to get this to work in Powershell on my box. When I start to run even the first line, I get "Select–String : The term 'Select–String' is not recognized as the name of a cmdlet, function, script file, or operable program."  Not really sure what's wrong with the code or my box. I tried switching the double-quotes to single-quotes in case that was part of the issue, but still no success.


Tuesday, October 6, 2015 - 4:09:17 PM - Tibor Nagy Back To Top (38831)

Hi Aaron,

Thank you for the great article. I just would like to add that in case strict corporate policies do not allow running msiinv.exe from an unverified source then you can still use this PowerShell command:

get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name

Regards:
Tibor















get free sql tips
agree to terms