Hi,
today i was trying to uninstall the the software using PowerShell.
i See few blog posts about uninstalling software using PowerShell they re recommending WMI to uninstall software using the .Uninstalled() method. But i think this method is not right because it don’t un-installed the software properly. Sometime uninstalling software using these method cause system/laptop to crash.
In my view, un-installation should be done by proper way.
Lets un-install winzip in a proper way. You can also script it.
we are going to use WMI but in another way.
Lets Start
lets see installed software first using the below command.
Get-WmiObject -Class win32_product
it is showing the list of all installed software.
Now see if we have winzip installed. we are piped the previous command to Where-Object and searching for name which contain winzip in it.
Get-WmiObject -Class win32_product | where { $_.Name -like "*Winzip*"}
Yes we have WinZip installed
Lets pipe the above command to Format-List to that we can see all the members of the Winzip.
Get-WmiObject -Class win32_product | where { $_.Name -like "*Winzip*"} | format-List *
This will give us all the member properties of Winzip. The property in which we are interested is “LocalPackage”
and you can see that install LocalPackage contains a path to a .msi executable file. and we can uninstall .msi files uisng MSIEXEC. lets check the which command line switches MSIEXEC support.
Simple run MSIEXEC and it will show you all the switches msiexec support. The switch which we are going to use is /x and /passive
lets combine the all commands together. I put the first command in to $Wzip variable.
- $Wzip = Get-WmiObject -Class win32_product | where { $_.Name -like "*Winzip*"}
- $Wzip.localPackage
Now try to run $Wzip.localPackage and this will show us the WinZip install source
msiexec /x $wzip.localpackage /passive
Hi Aman, I have been doing some research about this. Win32_product unfortunately is not the recommended class to use. It's very very slow and when you query it, it causes your application error log to fill up like crazy with the following error messages :
ReplyDelete"Windows Installer reconfigured the product. Product Name: Debugging Tools for Windows (x86). Product Version: 6.12.2.633. Product Language: 1033. Manufacturer: Microsoft Corporation. Reconfiguration success or error status: 0."
Even Microsoft doesn't recommend it.
"Win32_product Class is not query optimized. Queries such as “select * from Win32_Product where (name like 'Sniffer%')” require WMI to use the MSI provider to enumerate all of the installed products and then parse the full list sequentially to handle the “where” clause. This process also initiates a consistency check of packages installed, verifying and repairing the install. With an account with only user privileges, as the user account may not have access to quite a few locations, may cause delay in application launch and an event 11708 stating an installation failure.
Win32reg_AddRemovePrograms is a much lighter and effective way to do this, which avoids the calls to do a resiliency check, especially in a locked down environment. So when using Win32reg_AddRemovePrograms we will not be calling on msiprov.dll and will not be initiating a resiliency check. "
http://support.microsoft.com/kb/974524
I have seen similar messages on my Windows 7.
Just a word of advice.
I am working on one of my project to push out patches and hence the last step is to devise a method to roll back the patches. Hence i am trying to find a way to roll back the patch remotely, pretty much the same way, I push it. so researching.. thanks for the article.
Hi Punnet
ReplyDeleteYes i know about it and actually i was about to add a note for the same.
thanks for the advise dear :o)
thanks
aman
Very helpful.. It works perfectly fine :)
ReplyDelete