For many users, installing and uninstalling software involves navigating menus and clicking buttons. But beneath the graphical interface (GUI) lies a powerful command-line world, and within that world resides PowerShell. PowerShell offers an efficient and customizable way to manage software on your Windows system, giving you finer control over installations and uninstalls.
Before diving into PowerShell's magic, let's take a brief detour through the classic Windows command prompt. While not as user-friendly and powerful as PowerShell, it makes use of the msiexec.exe tool for basic MSI package installations. However, it lacks the flexibility and automation that PowerShell provides.
This article will guide you through leveraging PowerShell's capabilities for installing and uninstalling of MSI packages. We'll also explore logging options for MSI installations to keep track of the process.
PowerShell offers a powerful way to manage software on your Windows system. This article will guide you through installing and uninstalling both MSI and EXE packages using PowerShell, giving you greater control over your system's applications.
1. MSI Packages Installation
MSI (Microsoft Installer) packages are a common format for installing software on Windows. PowerShell utilizes the msiexec.exe tool for MSI installations.
Here's how we can install an MSI package using PowerShell. As previously mentioned, we will make use of msiexec nad therefore we'll be using Start-Process cmdlet from PowerShell.
Code: Select all
Start-Process msiexec.exe -Wait -ArgumentList "/i <path_to_msi_file> <installation_arguments>"
- /qn
Note: In order to install an MSI silently, the PowerShell prompt should be launched as an administrator.
- /L*V <path_to_log_file>
For more of the msiexec arguments, please refer to the following article: MsiExec.exe Command Line
2. MSI Packages Uninstallation
Uninstalling an MSI package can be done in more ways. The first way we will discover today is the use of /x argument of msiexec, which as opposed to /i means uninstall.
Approach #1
Code: Select all
Start-Process msiexec.exe -Wait -ArgumentList "/x <path_to_msi_file> /qn"
Approach #2
Here's when the second approach comes into play. For this approach, we will make use of Get-WmiObject cmdlet with its' Win32_Product class.
In order to identify the installed MSI, we can use multiple criterias, but today I will show you two of them: the application name and its' IdentifyingNumber (the ProductCode).
For example, if we run the following command:
Code: Select all
Get-WmiObject Win32_Product -Filter "name='MyApplication'"
As you can see, it gives us quite some details about the installed package.
Here's how we can run the Uninstall() method for an installed package, by using the name.
Code: Select all
$app = Get-WmiObject Win32_Product -filter "name='MyApplication'"
$app.Uninstall()
Approach #3
The third approach will be through using the Get-Package cmdlet with its' Uninstall-Package method.
Here's the command line to uninstall the MSI package:
Code: Select all
Get-Package -name "MyApplication" | Uninstall-Package
This should be it, I hope you found this article helpful.
See you in the next one.
Best regards,
Catalin