We've been doing way too many builds recently and the old routine of uninstalling the old build before running the build was getting tired so I did a bit of digging and found out how to remove an msi using PowerShell:
This is the part of the script that uninstalls the old build:
This is the part of the script that uninstalls the old build:
$data = gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select
DisplayName, DisplayVersion | where {$_ -match "MyApplication"}
if ($data)
{
$version = $data.DisplayVersion
echo "MyApplication is already installed. Current Version is $version"
echo "Uninstalling version $version"
$app = Get-WmiObject -Class Win32_product | Where-Object { $_.Name -match "MyApplication"}
$app.Uninstall() > $null
}
The main downside of this method is that it is very slow, but the upside is that it does not require manual intervention, so it allows one to get on with other stuff.
Sending the output of the $app.uninstall() call to $null ensures that no output is displayed to the screen. It might be desirable to provide some output.$exitcode = $app.Uninstall() echo "exit code: $($var.ReturnValue)"
No comments:
Post a Comment