$softwarePath = "C:\folder1\folder2"
# Installing msi1
$ODBC17 = "$softwarePath\msi01.msi"I can get 3 behaviors/errors.
If the execution line is below, I get
Start-Process msiexec -argumentlist /i $ODBC17 -wait ## OR with double quotes Start-Process msiexec -argumentlist /i "$ODBC17" -wait returning Start-Process : A positional parameter cannot be found that accepts argument 'C:\folder1\folder2\msi01.msi'.Start-Process msiexec -argumentlist '/i $ODBC17' -wait ## OR with double quotes Start-Process msiexec -argumentlist '/i "$ODBC17"' -waitIf I don’t use Start-Process, there won’t be any error. I will see a windows installer but it never actually executes the installation.
msiexec /i $ODBC17 -wait ## using single quotes, double quotes, or combinations does not make any difference

What I eventually wanted is:
To install the MSI file with PowerShell, we can use cmdlet Start-Process.
Let say we want to install the 7ZIP MSI file on the local computer and we have downloaded and stored the source file on the C:\temp location. Once we run the below command it will start the MSI installation.
Start-Process C:\Temp\7z1900-x64.msi
The above command will open the GUI to install the MSI file but we use PowerShell to avoid GUI interaction so we can add the argument to install the file.
If you check which arguments are available to run the MSI file, use the below command.
C:\Temp\7z1900-x64.msi /?
It will popup box like this,

We need here /quiet argument to install the 7zip silently.
Start-Process C:\Temp\7z1900-x64.msi -ArgumentList "/quiet"
If you want to see the progress bar in unattended mode add /Passive argument
Start-Process C:\Temp\7z1900-x64.msi -ArgumentList "/quiet /passive"
To install the MSI file on the remote server, we can use Invoke-Command.
Invoke-Command -ComputerName LabMachine2k16 -ScriptBlock{ Start-Process C:\Temp\7z1900-x64.msi -ArgumentList "/quiet"
}Kickstart Your
Get certified by completing the course
In this article, I will guide you through the process of installing MSI packages using PowerShell, covering basic installations and those requiring arguments. We will also explore the PowerShell App Deployment Toolkit (PSADT), which further streamlines the installation process.
Installing MSI Packages Through PowerShell
Start-Process 'msiexec.exe' -ArgumentList '/I "Path\To\Your\Package.msi" /qn' -Wait
In this script, `msiexec.exe` is the command-line utility for installing, modifying, and managing Windows Installer packages.
Start-Process 'msiexec.exe' -ArgumentList '/I "Path\To\Your\Package.msi" /L*V "Path\To\LogFile.log" /qb' -Wait
To avoid unintended system restarts, the `/norestart` flag is essential, providing control over the post-installation environment.
These silent installation capabilities are integral for efficient software deployment and management in automated or controlled settings, ensuring minimal disruption while maintaining comprehensive control over the installation process.
For an in-depth understanding of how to use the msiexec.exe command line for managing MSI packages, check this article.
Installing MSI with PowerShell App Deployment Toolkit
Uninstalling MSI with PowerShell
PowerShell also facilitates the uninstallation of MSI packages, offering a flexible method for software removal on Windows systems.
A typical method involves using the Get-WmiObject cmdlet to identify and execute the uninstall command for the desired package. This approach allows for targeted software removal based on specific criteria, such as the name or version of the software.
For example, let’s uninstall an application named “ExampleApp”.
First, we use the `Get-WmiObject` cmdlet to search for the installed application. Here’s how you might structure the PowerShell command:
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "ExampleApp" }This command searches for an installed product that matches the name “ExampleApp“. If the application is found, it’s assigned to the `$app` variable.
Next, to proceed with the uninstallation, we invoke the `Uninstall` method on the object contained in `$app`:
if ($app -ne $null) { $app.Uninstall()
} else { Write-Output "Application not found."
}This method checks if the application was found (`$app -ne $null`). If the application exists, the `Uninstall()` method is called to uninstall the application. If the application is not found, it outputs a message indicating that the application was not found.
It’s important to note a couple of considerations when using this method:
- The `Win32_Product` class method can be slow and may cause a reconfiguration of installed products. It enumerates every installed product and might trigger a consistency check on each, which can impact system performance.
- Using this approach in a script allows for automation in bulk uninstallation scenarios or as part of a larger maintenance script. However, for high-volume environments or critical systems, thorough testing is recommended to ensure compatibility and minimize disruptions.
This example demonstrates a straightforward way to uninstall software using PowerShell, leveraging the capabilities of Windows Management Instrumentation (WMI) for effective system management.
Uninstalling MSI with PowerShell App Deployment Toolkit
Using the PowerShell App Deployment Toolkit (PSADT) for uninstalling MSI packages offers enhanced control, especially in complex or large-scale environments.
Here’s how you can structure a script for uninstalling an application named “ExampleApp” using PSADT.
First, ensure you have the PSADT extracted and ready. You will be working primarily within the `Deploy-Application.ps1` script file, which is where you define your installation, uninstallation, and other custom actions.
To uninstall an MSI package with PSADT, open the `Deploy-Application.ps1` file and navigate to the `Uninstall` section.
Here’s an example of what the uninstallation would look like.
[scriptblock]$UninstallApplication = { # Specify the MSI product code or the name of the application you wish to uninstall $productCode = '{12345678-90AB-CDEF-1234-567890ABCDEF}' # Example MSI product code $appName = "ExampleApp" # Example application name # Attempt to find and uninstall the application by its product code Execute-MSI -Action Uninstall -Path $productCode # Alternatively, if you don't have the product code, you can uninstall by name # This method relies on finding the application in the registry and then uninstalling it Remove-MSIApplications -Name $appName # Additional cleanup actions can be performed here if necessary
}n this script, we use the `Execute-MSI` function to remove an MSI package using its unique product code, making sure we uninstall the right app.
If you don’t know the product code or prefer using the app’s name, the `Remove-MSIApplications` function can be used. This is handy if you’re dealing with several versions of an app or if the product code isn’t clear.
The PSADT offers detailed logging by default, which helps in troubleshooting and verifying the uninstallation process. Logs are typically found in the `Logs` folder within the PSADT directory, providing a comprehensive record of the script’s execution.
Before running the script, ensure that the toolkit’s files (`Deploy-Application.exe`, `Deploy-Application.ps1`, etc.) are located in the same directory.
To initiate the uninstallation process, run the `Deploy-Application.exe` with the `-DeploymentType Uninstall` parameter:
Deploy-Application.exe -DeploymentType Uninstall
Conclusion
Whether you’re a seasoned IT professional or new to software deployment, these tools provide the flexibility and efficiency needed in today’s fast-paced IT environments.
Stay ahead in the world of software packaging and deployment by subscribing to our newsletter.
Popular Articles
DESCRIPTION
If the -Action parameter is set to “Install” and the MSI is already installed, the function will exit.
Sets default switches to be passed to msiexec based on the preferences in the XML configuration file.
Automatically generates a log file name and creates a verbose log file for all msiexec operations.
Expects the MSI or MSP file to be located in the “Files” sub directory of the App Deploy Toolkit.
Expects transform files to be in the same directory as the MSI file.
OUTPUTS
PSObject
Returns a PSObject with the results of the installation
– ExitCode
– STDOut
– STDErr
INPUTS
None
You cannot pipe objects to this function.
PARAMETERS
-Action
The action to perform.
Options: Install, Uninstall, Patch, Repair, ActiveSetup.
Accept pipeline input
Accept wildcard characters
-Path
The path to the MSI/MSP file or the product code of the installed MSI.
Accept pipeline input
Accept wildcard characters
-Transform
The name of the transform file(s) to be applied to the MSI.
The transform file is expected to be in the same directory as the MSI file.
Multiple transforms have to be separated by a semi-colon.
Accept pipeline input
Accept wildcard characters
-Parameters
Overrides the default parameters specified in the XML configuration file.
Install default is: “REBOOT=ReallySuppress /QB!”.
Uninstall default is: “REBOOT=ReallySuppress /QN”.
Accept pipeline input
Accept wildcard characters
-AddParameters
Adds to the default parameters specified in the XML configuration file.
Install default is: “REBOOT=ReallySuppress /QB!”.
Uninstall default is: “REBOOT=ReallySuppress /QN”.
Accept pipeline input
Accept wildcard characters
-SecureParameters
Hides all parameters passed to the MSI or MSP file from the toolkit Log file.
Accept pipeline input
Accept wildcard characters
-Patch
The name of the patch (msp) file(s) to be applied to the MSI for use with the “Install” action.
The patch file is expected to be in the same directory as the MSI file.
Multiple patches have to be separated by a semi-colon.
Accept pipeline input
Accept wildcard characters
-LoggingOptions
Overrides the default logging options specified in the XML configuration file.
Default options are: “/L*v”.
Accept pipeline input
Accept wildcard characters
-private:LogName
Overrides the default log file name.
The default log file name is generated from the MSI file name.
If LogName does not end in .log, it will be automatically appended.
For uninstallations, by default the product code is resolved to the DisplayName and version of the application.
Accept pipeline input
Accept wildcard characters
-WorkingDirectory
Overrides the working directory.
The working directory is set to the location of the MSI file.
Accept pipeline input
Accept wildcard characters
-SkipMSIAlreadyInstalledCheck
Skips the check to determine if the MSI is already installed on the system.
Default is: $false.
Accept pipeline input
Accept wildcard characters
-IncludeUpdatesAndHotfixes
Include matches against updates and hotfixes in results.
Accept pipeline input
Accept wildcard characters
-NoWait
Immediately continue after executing the process.
Accept pipeline input
Accept wildcard characters
-PassThru
Returns ExitCode, STDOut, and STDErr output from the process.
Accept pipeline input
Accept wildcard characters
-IgnoreExitCodes
List the exit codes to ignore or * to ignore all exit codes.
Accept pipeline input
Accept wildcard characters
-PriorityClass
Specifies priority class for the process.
Options: Idle, Normal, High, AboveNormal, BelowNormal, RealTime.
Default: Normal
Accept pipeline input
Accept wildcard characters
-ExitOnProcessFailure
Specifies whether the function should call Exit-Script when the process returns an exit code that is considered an error/failure.
Default: $true
Accept pipeline input
Accept wildcard characters
-RepairFromSource
Specifies whether we should repair from source.
Also rewrites local cache.
Default: $false
Accept pipeline input
Accept wildcard characters
-ContinueOnError
Continue if an error occurred while trying to start the process.
Default: $false.
Accept pipeline input
Accept wildcard characters
CommonParameters
EXAMPLES
EXAMPLE 1
Installs an MSI
EXAMPLE 2
Installs an MSI, applying a transform and overriding the default MSI toolkit parameters
EXAMPLE 3
Installs an MSI and stores the result of the execution into a variable by using the -PassThru option
EXAMPLE 4
Uninstalls an MSI using a product code
EXAMPLE 5
Installs an MSP
SYNTAX




