Skip to content

Instantly share code, notes, and snippets.

@zhilich
Created November 6, 2017 03:29
Show Gist options
  • Save zhilich/522c33f863bb8e0a18ff80657b88315b to your computer and use it in GitHub Desktop.
Save zhilich/522c33f863bb8e0a18ff80657b88315b to your computer and use it in GitHub Desktop.
Installing MSI several times
param (
[Parameter(Mandatory=$false)][string]$Instance
)
[string]$DefaultInstance = "MyProduct_MSI"
if ($Instance) {
Write-Host "Copying installer to $($Instance).msi"
Copy-Item "MyProduct_MSI.msi" "$($Instance).msi"
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$utf8 = new-object -TypeName System.Text.UTF8Encoding
$hash = (new-object -TypeName System.Guid -ArgumentList @(,$md5.ComputeHash($utf8.GetBytes($Instance)))).ToString().ToUpper()
Write-Host "Product code: $($hash)"
Write-Host "Injecting product code into $($Instance).msi"
Invoke-Expression -Command:"cscript wirunsql.vbs $($Instance).msi ""UPDATE Property SET Value='{$($hash)}' WHERE Property='ProductCode'"""
Invoke-Expression -Command:"cscript wirunsql.vbs $($Instance).msi ""UPDATE Property SET Value='MyProduct ($($Instance))' WHERE Property='ProductName'"""
Invoke-Expression -Command:"cscript wirunsql.vbs $($Instance).msi ""UPDATE Property SET Value='{$($hash)}' WHERE Property='UpgradeCode'"""
Invoke-Expression -Command:"cscript wisuminf.vbs $($Instance).msi Revision='{$($hash)}'"
}
else {
$Instance = $DefaultInstance
}
Write-Host "Launching installer package..."
Invoke-Expression -Command:"msiexec /i $($Instance).msi"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment