- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to uninstall the MSI package using PowerShell?
To uninstall the MSI package using PowerShell, we need the product code and then the product code can be used with msiexec file to uninstall the particular application.
Product code can be retrieved using the Get-Package or Get-WmiClass method. In this example, we will uninstall the 7-zip package.
$product = Get-WmiObject win32_product | ` where{$_.name -eq "7-Zip 19.00 (x64 edition)"}
$product.IdentifyingNumber
The above command will retrieve the product code. To uninstall the product using msiexec, use /x switch with the product id. The below command will uninstall the 7-zip using the above-retrieved code.
msiexec /x $product.IdentifyingNumber /quiet /noreboot
This is the cmd command but we can run in PowerShell, however we can’t control the execution of this command. For example, the next command after this would be executed immediately. To wait until the uninstall completes, we can use the Start-Process in PowerShell which uses the -Wait argument.
Start-Process "C:\Windows\System32\msiexec.exe" ` -ArgumentList "/x $($product.IdentifyingNumber) /quiet /noreboot" -Wait
To run the same commands on the remote computers, use Invoke-Command.
Invoke-Command -ComputerName TestComp1, TestComp2 ` -ScriptBlock { $product = Get-WmiObject win32_product | where{$_.name -eq "7-Zip 19.00 (x64 edition)"} $product.IdentifyingNumber Start-Process "C:\Windows\System32\msiexec.exe" ` -ArgumentList "/x $($product.IdentifyingNumber) /quiet /noreboot" -Wait }
- Related Articles
- How to install the MSI package using PowerShell DSC?
- How to uninstall software using Package management in PowerShell?
- How to retrieve the MSI package product code using PowerShell?
- How to install the MSI file using PowerShell?
- How to uninstall software using WMI in PowerShell?
- How to uninstall the PowerShell Module?
- How to install MSI file to the custom directory using PowerShell?
- How to install MSI file using batch file in PowerShell?
- How to install the Nuget Package using PowerShell?
- Get the Reverse Shell with MSI package
- How to uninstall a VPN
- How to install pandas using the python package manager?
- How to format the disk using PowerShell?
- How to work the timezone using PowerShell?
- How to traceroute using PowerShell?
