How to install and un-install *.msi package with PowerShell and msiexec

If you want to install a *.msi package by first un-installing the product and then installing, you can use the following PowerShell script:

Use System.Diagnostics.Process.Start function and the WaitForExit function to make sure the product is un-installed before it is installed.


# This scripts needs unrestricted access
Set-ExecutionPolicy Unrestricted

# Change working directory to script directory
function Get-ScriptDirectory
    $Invocation = (Get-Variable MyInvocation -Scope 1).Value
    Split-Path $Invocation.MyCommand.Path
$scriptFolder = Get-ScriptDirectory

# Un-Install Database
$parameters = "/qn /x {B381D4FB-7A5C-4794-8997-8CAAF2847E20}"
$uninstallStatement = [System.Diagnostics.Process]::Start( "msiexec", $parameters )
# Install Database
$parameters = "/qn /i " + $scriptFolder + "\Sales.Database.Setup.msi"
$installStatement = [System.Diagnostics.Process]::Start( "msiexec", $parameters )

Leave a Reply

Your email address will not be published. Required fields are marked *

One comment

  1. Sagun says:


    I have a .MSI file on a network share and want to uninstall and install silently as I need to deploy this via Active Directory using powershell to multiple computers across the network, I’m confused where I would replace with the network share location and actual .MSI setup file, can you let me know? I’m very new to powershell, thanks.


    Bluebeam Revu x64 11.msi