THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Rob Farley

- Owner/Principal with LobsterPot Solutions (a MS Gold Partner consulting firm), Microsoft Certified Master, Microsoft MVP (SQL Server) and leader of the SQL User Group in Adelaide, Australia. Rob is also a Director of PASS, and runs training courses around the world in SQL Server and BI topics.

PowerShell script to help uninstall SQL Server 2008 R2 Evaluation Edition

If you haven’t been caught by a client (or even yourself) installing SQL 2008 R2 Evaluation Edition and then letting it expire, you might not realise the pain that this causes. To say it’s frustrating is a serious understatement.

Fellow SQL MVP and SQLBlog blogger Aaron Bertrand (@aaronbertrand) has an excellent post on the matter, which he put together back in October 2010. I had cause to use it recently, but got somewhat put off by searching through the registry.

So I put a line of PowerShell together (which I’ve split across 5 for easier reading):

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
select @{Name='Guid';Expression={$_.PSChildName}}, @{Name='Disp';Expression={($_.GetValue("DisplayName"))}} |
where-object {$_.Disp -ilike "*SQL*R2*"} |
where-object {$_.Guid -like '{*'} |
% {"rem " + $_.Disp; 'msiexec /x "' + $_.Guid + '"'; ''} > uninstallR2.bat

If you run this, it will produce the file that Aaron recommended. You can look down it for anything you don’t want to get rid of, and maybe reorder the odd thing, and then run it. Then you should be able to install Developer Edition, and breathe much easier.

The script is quite straight forward, it just lists everything in the uninstall bit of the registry, gets the DisplayName values out, filters them, and outputs the results in a few lines for the batch file. Nothing amazingly complicated, but useful for getting through the list quickly.

(Big thanks to Aaron for working out what was required for the uninstall, and Aaron Nelson (@sqlvariant) for answering a quick question when I was putting the final touches on the script)

Published Tuesday, May 24, 2011 2:04 AM by Rob Farley
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



Frank Q said:

What I have to change in this script to uninstall SQL Server 2008 evaluation after I have installed SQL Server 2008 R2?

May 29, 2011 7:19 AM

Rob Farley said:

Hi Frank,

Tweak the bit that says *SQL*R2*. You could even just put * and then go through the resultant batch file to look for the things you want to keep. But maybe keep the *SQL* bit and then look for the stuff you want to get rid of.


May 29, 2011 7:52 AM

THeo said:

I created the uninstallR2.bat file using the PowerShell script provided above.

Unfortunately the bat file does not run.

I get a message telling me that

"_R" is not recognized as an internal or external command, operable program or batch file"

Note the under score is actually a square symbol.

I am wondering if the bat file name or location is my issue?

I looked at the services running and found MsDtsServer100 running so I stopped it. Maybe there are other SqlServer services to stop?

I also ran the bat file as administrator.

Any assistance will be appreciated.

March 25, 2012 11:34 AM

Rob Farley said:

Hi Theo - what's in your .bat file? Does it contain any strange characters?

March 25, 2012 5:56 PM

Theo said:

Hi Rob, to the eye nothing noticeable.

As an experiment I REM all the msiexec and the error still occurs.

I created a bat file with a couple of REM lines and it worked ok.

The UninstallR2.bat result I got running your powershell script gave me 23 msiexec lines comparing to Aaron Bertrand's seems excessive?

March 25, 2012 9:33 PM

Theo said:

Given that I have never used Powershell scripting before I became suspicious that maybe the file did not get created with the correct properties.

So I copied the contents into another file I created using note pad and it is now running.

Not sure what the issue was, maybe Powershell needs configuring?

March 25, 2012 9:52 PM

Rob Farley said:

(just started typing again)

Yes - I suppose it's possible that somewhere along the way there's a strange character getting inserted instead of a space. I'm pleased you've got it working.

March 25, 2012 9:56 PM

Theo said:

Thanks for your help.

The bat file generated 23 uninstall commands, working through the registry would have been a time consuming trial and error exercise.

I ran the bat file 3 times, on the 3rd run it didn't find anything to uninstall.

However, under Start-All Programs I still see some Sql Server 2008 menu options.

I can still run the Installation Center, documentation and tutorials and Visual Studio.

I will try to install the developer edition tonight and see if that works.

March 26, 2012 5:26 AM

Rob Farley said:

You might see some SQL 2008 entries still, because you were only looking for R2 stuff. If you tweak the script a little, you can probably find the list of SQL 2008 things too.

March 26, 2012 5:48 AM

Theo said:

Thanks the only item I couldn't remove was the Sql Server 2008 R2 documentation.

I will try to install the developer edition now and see if all goes well.

March 27, 2012 10:26 AM

Alex said:

The odd characters are unicode. If you save the batch file using notepad, save as, and specify ANSI rather than Unicode, it should work fine

June 22, 2012 10:44 PM

Stef Locke said:

I just used this to give my infrastructure guys an uninstall script for all my various bits of sql server lying around.  This has saved me so much time and if they say it doesn't work, then I'll chuck it into notepad and save as ANSI.  I've been looking for something like this for ages.  Great work!

August 31, 2012 10:03 AM

llyjak said:

Thanks, you 've saved lot of my time :) Nice job !

October 19, 2012 3:55 PM

Ross Gallagher said:

Hi Rob,

I am trying to use your script to help me remove a SQL Server 2008 R2 installation but when I run it I get this message below:

Get-ChildItem : A parameter cannot be found that matches parameter name 'System.Object[]'.

Should I be able to just run your script exactly the way you have written it ?


January 30, 2013 5:01 PM

Rob Farley said:

It runs just fine on my machine as is.

Try changing directory one level at a time into HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall to make sure you can. Then slowly add the rest of the script to see what fails.

Could be you don't have enough privilege? You could try making sure you have admin rights escalated in your PowerShell window (ie, Run As Administrator).

January 31, 2013 5:33 AM

Ed said:

Brilliant, thanks! Service Pack 1 was not picked up by the script, and I am unable to uninstall it or a hot fix I had installed. Be sure to remove those first before uninstalling sql server.

June 20, 2013 7:18 PM

Leave a Comment


This Blog


Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement