Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I downloaded the script below to help me uninstall a problematic SQL Server install, when I try and run it in the PS editor I receive an error

HTML
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:40


msiinv.exe I downloaded from a link on the same site. Here is the script, I've never used PS before and Google didn't find much of help


HTML
$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 "\t", ""
$a = $a -replace "}","}"""
$a | Out-File c:\BatFiles\remove.bat -encoding ascii


What I have tried:

All of the above and lots of swearing
Posted
Updated 31-May-20 13:51pm
Comments
Patrice T 4-May-16 9:33am    
Ask the author of that script!

Select-String didn't show up in PowerShell until version 3.0. You're probably running an earlier version of PowerShell.

Update the version of PowerShell on the machine and you should be good to go.
 
Share this answer
 
Comments
pkfox 4-May-16 10:09am    
Ok thanks I'll try updating it
pkfox 4-May-16 10:20am    
Hi Dave, I updated to version 4 and still the same error :-(
Dave Kreskowiak 4-May-16 10:41am    
Very odd. What comes back if you type $PSVersionTable.PSVersion
at the PowerShell command prompt?
pkfox 4-May-16 10:48am    
PS C:\Users\pjk> $PSVersionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
4 0 -1 -1
Dave Kreskowiak 4-May-16 10:52am    
In that case, I have no idea what's wrong. I would try uninstalling PowerShell and reinstalling it from the 4.0.
Try this, it worked for me:
$a = d:\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 d:\temp\remove.bat -encoding ascii;
 
Share this answer
 
Comments
CHill60 1-Jun-20 4:33am    
You are still using Select-String so the error would still occur for the OP - they did not have .NET 4.5 installed.
It's also good to explain what you changed from the original code and why - how does changing the Context help for example
For those with the same issue.

Even with the error message, the remove.bat file is generated.
Open it and replace manually (I used notepad++ to replace the file):

P.E, my file was writing the lines like this:
rem Microsoft SQL Server System CLR Types
  Product code:{C3F6F200-6D7B-4879-B9EE-700C0CE1FCDA}"

On my case I had to replace the Product code: to msiexec /x "
In order to have the code formatted correctly, like this:
rem Microsoft SQL Server System CLR Types
  msiexec /x "{C3F6F200-6D7B-4879-B9EE-700C0CE1FCDA}"


Now that you formatted everything, just run as admin and it should work well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900