I am trying to uninstall a custom app using the UninstallString from the registry. I am getting this error :
‘The term ‘MsiExec.exe /I{4C659685-5409-49BC-8A4E-CA42933589CF}’ 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’
here is the code i am using, any help would be greatly appreciated
$Script = {
$DisplayName = "*CMS*"
$keys = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
$items = $keys | Foreach-Object { Get-ItemProperty $_.PsPath }
$CMS = foreach($item in $items){if(($item.DisplayName) -and ($item.DisplayName -like $displayName)){$item}}
& $cms.UninstallString
}
Invoke-Command -ScriptBlock $Script -Session $s
I also tried this
$Script = {
$cms = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object {$_.DisplayName -like "*CMSGenIISetup*" } |
Select-Object -Property DisplayName, UninstallString
write $cms
ForEach ($ver in $cms ) {
If ($ver.UninstallString) {
$uninst = $ver.UninstallString
& cmd /c $uninst /quiet /norestart
}
}
}
Invoke-Command -ScriptBlock $Script -Session $s
and received this message even though it is still installed
DisplayName : CMSGenIISetup
UninstallString : MsiExec.exe /I{4C659685-5409-49BC-8A4E-CA42933589CF}
PSComputerName : LNtestBOX
RunspaceId : 6007e80f-8133-404a-92ad-2b689c085912
T h i s a c t i o n i s o n l y v a l i d f o r p r o d u c t s t h a t a r e c u r r e n t l y i n s t a l l e d .
Hey fella, might be worthwhile try it as a Start-Process, with msiexec.exe as the process to start, and the additional /i etc as the arguments
Oddly, I’ve also found that windows installer packages can usually be sparked directly when i’ve used it, even without the ‘&’. Only difference being I install them and change to the dir of the source file first.
e.g.
msiexec.exe /i SQLSERVER2008_ASAMO10.msi /qb
NB For uninstallation, /x is a better bet.
Try these and let me know how you get on.
Hey Tim
which example should i try it? can you show me exactly where you would put it?
as always thank you
I tried this and still didn’t uninstall
ForEach ($ver in $cms ) {
If ($ver.UninstallString) {
$uninst = $ver.UninstallString
Start-Process cmd -ArgumentList "/c $uninst /quiet /norestart" -NoNewWindow
}
}
I mean using start-process with msiexec as the executable, and the /x guid /qn as the arguments.
But also try straight
msiexec /x guid /qn
as well
i tried this … no luck
$SCRIPT = {
Start-Process msiexec.exe -ArgumentList '/x {4C659685-5409-49BC-8A4E-CA42933589CF} /qn'
}
Invoke-Command -ScriptBlock $Script -Session $s
It worked with other apps just not this in house custom one
Ah, okay. I guess the thing to do first is to invoke it directly on the box itself with the same command (minus scriptblock of course). Does it work when you do that?
Do yo mean this?.. still did not uninstall
$script = {
$script = {
$MSI = "C:\Windows\System32\msiexec.exe"
$args = '/x {D1969B0D-FA69-48CF-9732-A0E09AB6DBD0} /qn'
Invoke-Expression -Command "$MSI $Arguments"
}
Invoke-Command -ComputerName $pc -ScriptBlock $script
I mean just run the Start-Process xxxx code directly on the box, so you can visibly see what’s going on.
You could also use the logging switches for msiexec to get details of exactly what’s happening. I think it’s a good idea to see if it is prompting for anything, or if it’s trying to access any network resources.
The issue was when the package was installed it was set for just you vs everyone. When I installed with everyone I was able to use WMI
$Script = {
$app = Get-WmiObject -Class Win32_Product |where { $_.name -EQ 'CMSGenIISetup' }
$app.uninstall()
}
Invoke-Command -ScriptBlock $Script -Session $s -Verbose
Thank you for all your Help!