The built-in PowerShell Package Manager is unreliable when it comes to installing and removing software packages in the MSI format. However, there is an excellent open source Windows Installer PowerShell module provided by Heath Stewart for performing many tasks with MSI installers and MSI-based installations.

You can install the module from the PowerShell Gallery using the following command:

Install-Module MSI

Installing MSIs

While you can use the standard msiexec command line for installing your MSIs, the command below is built with PowerShell in mind. This means it always executes silently and returns progress, warnings, and errors directly to the PowerShell pipeline.

Install-MSIProduct .\example.msi

The same features apply to the other cmdlets provided for modifying or removing existing installations: Install-MSIPatch, Repair-MSIProduct, Uninstall-MSIPatch, and Uninstall-MSIProduct.

Getting information

Sometimes you have to get information from the MSI file without installing the program. You can easily accomplish this using the following command:

Get-MSIProperty -Path .\example.msi

If we run this against an MSI for installing the Microsoft Deployment Toolkit (MDT), we get the following results:

Information displayed from the Get MSIProperty command

Information displayed from the Get MSIProperty command

Get-MSIProductInfo easily retrieves information on existing installations:

Get-MSIProductInfo | where {$_.Productname -like "*sharepoint*"}

The above example will show us all the installations with a product name matching SharePoint.

Results from the Get MSIProductInfo command

Results from the Get MSIProductInfo command

Uninstalling MSIs

We can also pipe the results of this command to other commands so we can modify existing installations.

Get-MSIProductInfo | where {$_.Productname -like "*sharepoint*"} | Uninstall-MSIProduct

The above example removes all installed products on the PC that have a product name matching SharePoint.

Generating DSC configurations

A simple use case example is generating a DSC configuration. Let's say you need to script a configuration for servers using the Microsoft Desired State Configuration Package resource. The documentation specifies that we have three required parameters: Name (package name), Path (location of the package), and ProductId (unique identifier).

The ProductId and the Name both need to come from the MSI for the DSC to work properly. Depending on the number of MSIs you have, this could quickly become a pain. Using the MSI module though, we can quickly loop through all the MSIs in a directory and automatically create our configuration. We're using code to write our code!

Get-ChildItem *.msi | foreach {
    $ProductName = (Get-MSIProperty -Path $_.FullName -Property ProductName).Value
    $ProductCode = (Get-MSIProperty -Path $_.FullName -Property ProductCode).Value
    $DSCPackagename = $_.Name.TrimEnd(".msi")
    $MSIFileName = $_.Name
    package $DSCPackagename
        Name = '$ProductName'
        Path = '\\MyPackageShare\$MSIFileName'
        ProductId = '$ProductCode'
        Arguments = '/qn'
        Ensure = 'Present'

Running this simple script in a directory with a couple of MDT MSIs yields the following configuration script ready for copying and pasting into an existing configuration:

Subscribe to 4sysops newsletter!

package MicrosoftDeploymentToolkit2013_x64
    Name = 'Microsoft Deployment Toolkit 2013 Update 2 (6.3.8330.1000)'
    Path = '\\MyPackageShare\MicrosoftDeploymentToolkit2013_x64.msi'
    ProductId = '{F172B6C7-45DD-4C22-A5BF-1B2C084CADEF}'
    Arguments = '/qn'
    Ensure = 'Present'
package MicrosoftDeploymentToolkit_x64
    Name = 'Microsoft Deployment Toolkit (6.3.8443.1000)'
    Path = '\\MyPackageShare\MicrosoftDeploymentToolkit_x64.msi'
    ProductId = '{9547DE37-4A70-4194-97EA-ACC3E747254B}'
    Arguments = '/qn'
    Ensure = 'Present'
  1. Leos Marek (Rank 4) 6 years ago

    Hi Micah,

    is it possible to use this remotely with invoke-command or enter-pssession?

    In case yes does this support msi to be located on unc share? Is it able possible to do such installation over slow wan? (1mbps)

    thanks L

    • Author

      Hi Leos,

      As long as the module is installed on the remote PCs I would expect it to work as expected with PSRemoting.

      It would work with MSIs from a UNC share but of course I would not recommend using it over a slow internet connection like you had mentioned. I would not expect to see any network performance benefits when downloading files over UNC over using something like msiexec.

      That being said, the author of the module might be able to answer your question more directly and I am sure he would appreciate you filing an issue on Github if you do find any bugs with the software or have any feature requests.

  2. sylvia 5 years ago

    I am trying to install a custom application using the below methods-
    1.$arg1 = “/qn”;
    $arg2 = ‘/L*V “‘ + $serviceLogging + ‘”‘;
    Start-Process -FilePath “C:\temp\GACintegration Server (x86) Setup(” -ArgumentList “/i $arg1$arg2″ -Wait;
    2.Start-Process msiexec.exe -ArgumentList ‘/I C:\Temp\GACintegration Server (x86) Setup2.2.13.1.msi Password=”04VqhJL6qOF2RYM8NJOE”‘ -Wait -NoNewWindow
    3.$Path = ‘msiexec’
    $ArgList = @(‘/i’,'”C:\Temp\GACintegration.msi”‘,”Service Account=`”.\GACINTEGRATION”`”,”Password=`”$04VqhJL6qOF2RYM8NJOE`””)
    Start-Process -FilePath $Path -ArgumentList $ArgList -Wait -NoNewWindow
    Start-Process -FilePath “C:\temp\GACintegration Server (x86) Setup2.2.13.1.msi” -ArgumentList “/qn”, “/l*vs”, “msifilename-logname.log” -Wait

    but all methods are failing with the msi installer window showing the argument list. Please help. I am trying this
    on Win2008r2 server

Leave a reply

Please enclose code in pre tags

Your email address will not be published.


© 4sysops 2006 - 2023


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account