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 )
$uninstallStatement.WaitForExit()
# Install Database
$parameters = "/qn /i " + $scriptFolder + "\Sales.Database.Setup.msi"
$installStatement = [System.Diagnostics.Process]::Start( "msiexec", $parameters )
$installStatement.WaitForExit()

Tags:

Leave a Reply