Is there a simple way to hook into the standard 'Add or Remove Programs' functionality using PowerShell to uninstall an existing application? Or to check if the application is installed?
+12
A:
$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "Software Name"
}
$app.Uninstall()
Edit: Rob found another way to do it with the Filter parameter:
$app = Get-WmiObject -Class Win32_Product `
-Filter "SELECT * FROM Win32_Product WHERE Name = 'Software Name'"
Your mileage my vary, but I can't get this version to work on my machine. I get this error (with what I think is a valid 'Software Name'):
Get-WmiObject : Invalid query
Jeff Hillman
2008-09-22 07:17:01
After a bit of research you can also use the -filter clause of Get-WmiObject:$app = Get-WmiObject -Class Win32_Product -filter "select * from Win32_Product WHERE name = 'Software Name'"
Rob Paterson
2008-09-22 07:44:57
This WMI class takes FOREVER to enumerate. I suggest Jeff that you update your code to include Rob's tip.
halr9000
2008-09-23 16:18:21
I agree with Jeff... my version doesn't seem to be working now....
Rob Paterson
2008-10-01 05:32:57
This WMI class is only available after being installed. Its not default part of XP or Windows 2003. Its default on Vista/2008
James Pogran
2009-02-05 04:51:01
If you get a "generic failure", this hotfix http://support.microsoft.com/kb/970553/ may help
David Gardiner
2009-11-03 05:38:17
+1
A:
Jeff Hillmans answer is pretty much it, I would say that it may be better to use IdentifyingNumber rather than the name, just in case.
Tubs
2008-09-22 07:31:28
+1
A:
Note that looking at WMI will only work for products that were installed via an MSI.
EBGreen
2008-09-22 15:24:02
+6
A:
To fix up the second method in Jeff Hillman's post, you could either do a:
$app = Get-WmiObject
-Query "SELECT * FROM Win32_Product WHERE Name = 'Software Name'"
Or
$app = Get-WmiObject -Class Win32_Product `
-Filter "Name = 'Software Name'"
Robert Wagner
2009-01-29 07:02:12