 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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    }