Installing, repairing, and uninstalling products and patches

New for version 2.2.0
All install, repair, and uninstall cmdlets log verbosely to the $env:TEMP directory by default using the pattern MSI-*.log. These logs are timestamps and may be additional sortable with a step identifier (e.g. installing a patch applicable to multiple products will have the same base log name but incremental step identifiers). This is the same as my specification for logging as used in the Burn chainer for WiX.

All cmdlets will also prompt for UAC consent, if required, unless you pass the -Force parameter. This is consistent with msiexec.exe. If you want to use these cmdlets in unattended automation scripts, I recommend you pass -Force or the scripts may block waiting for user input until the UAC consent dialog times out and fails the install.

Note: If product and patch packages are installed with a chainer like Visual Studio that you install, repair, and uninstall the product using that chainer. There may be additional logic and properties applied during those operations you don't know about.

Basic install

By default, all packages are installed with separate progress bars. This best mimics the behavior of Windows installer.

install-msiproduct product.msi

For product packages that support it, you can also redirect the target directory (TARGETDIR) using the -Destination parameter (alias: -TargetDirectory).

install-msiproduct product.msi -target C:\Product

Add features to an installed product

You can also pass any number of properties like you would to msiexec.exe to, for example, add features to an installed product. Notice how you don't need to specify a parameter name if all required parameters are assigned.

install-msiproduct "{851278A4-852F-410A-9FF7-B345C41DBE35}" ADDLOCAL=OptionalFeature

If you pipe the product installation to install-msiproduct, just pass additional properties after the -Properties parameter.

get-msiproductinfo "{851278A4-852F-410A-9FF7-B345C41DBE35}" | install-msiproduct -properties ADDLOCAL=OptionalFeature

Forcibly reinstalling all components

The default REINSTALLMODE is "omus", but you can use a different mode - either by tab-completed enumerations or the single characters used by Windows Installer.

repair-msiproduct "{851278A4-852F-410A-9FF7-B345C41DBE35}" -reinstall FileReplace, MachineData, UserData, Shortcut

This is equivalent to the REINSTALLMODE of "amus", which you can also use in the following pipeline example.

get-msiproductinfo "{851278A4-852F-410A-9FF7-B345C41DBE35}" | repair-msiproduct -reinstall "amus"

Uninstall all products matching a pattern

If you have a group of related products you want to uninstall and show a single, unified progress bar using the -Chain parameter (which all the cmdlets mentioned here support), you can use the following command.

get-msiproductinfo -name "*My Product*" | uninstall-msiproduct -chain -force

This will also remove any patches applied to those products.

Installing all advertised features on a machine

In an old - but still relevant - blog post I described the conditions, problems, and resolution of how features can be incidentally advertised. Here is an example using these cmdlets to fix the problem instead of Windows Script referenced in the solution.

Note: Some products actually use advertisement as a supported feature (e.g. Microsoft Office) but running a command like the following would fix both incidentally advertised features and merely install advertised features even if intended.

get-msiproductinfo | get-msifeatureinfo | where { $_.State -eq "Advertised" } | group ProductCode | select @{l="ProductCode"; e={$_.Name}}, @{l="CommandLine"; e={"ADDLOCAL=$(($_.Group | select -expand Name) -join ',')"}} | foreach { $_ | install-msiproduct -properties $_.CommandLine }

Last edited Jul 3, 2013 at 7:24 PM by heaths, version 2


No comments yet.