Executing old tools (cmd.exe)

Hi Folks,

So, I am running into a problem where I can’t seem to run the command without getting the following error message. Can someone give me some pointers as to what I am doing wrong? I am pulling the uninstall command from the registry and sending that information into a the variable $UninstallCMDfor the installed application and appending “/qn /norestart”. When I do this, I get the error message below.

Command= cmd.exe /c ($UninstallCMD) /qn /norestart

‘/qn’ is not recognized as an internal or external command, operable program or batch file.

Thanks for any pointers I may receive.

It depends pretty much on the uninstall string you get from the registry and how you try to execute it.
BTW: Whatfor cmd? Powershell is a command line shell and is able to run either internal and external commands or tools. No need to start another command line shell from the current command line shell. :wink:

You can use the example below and see if that works. If you put the ‘–%’ after the external command Powershell will not try to parse any of it.

c:\windows\system32\sc.exe --% qc bits

Whatever switches or values you would use for that command in the command prompt just add after the two dashes and percent.

Generally speaking, as we cannot see what the actual uninstall variable string is, I would recommend you alter your syntax and make use of Start-Process:

Start-Process -FilePath "cmd.exe" -ArgumentList '/c $UninstallCMD', '/qn' '/norestart'

However, given that from this syntax you can guess that $UninstallCMD is just a standard CMD command, you need not actually invoke cmd.exe to do this. Split your uninstall string into the executable being invoked (I’m guessing probably msiexec.exe?) and the arguments, and do it like this:

Start-Process -FilePath "msiexec.exe" -ArgumentList $Arguments, '/qn', '/norestart'