Use Power to get MSI Properties

Read a great post today by Nickolaj regarding reading MSI packages in powershell:

I had developed some earlier scripts a while back for reading MSI packages in powershell, but the scripts were … well … ugly, with an external COM xml type library.

Nickolaj’s script got me thinking how to improve my version, so I updated it and will post here:

The main difference between my version and the one by Nickolaj, is that this script will return all Properties, rather than only those properties requested when calling. This helps in discovery of available properties.

param(
[parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({Test-Path $_})]
[IO.FileInfo]$Path
)

$WindowsInstaller = New-Object -com WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember(
"OpenDatabase","InvokeMethod",$Null,
$WindowsInstaller,@($Path.FullName,0))

$View = $MSIDatabase.GetType().InvokeMember(
"OpenView","InvokeMethod",$null,
$MSIDatabase,"SELECT * FROM Property")

$View.GetType().InvokeMember(
"Execute", "InvokeMethod", $null, $View, $null)
while($Record = $View.GetType().InvokeMember(
"Fetch","InvokeMethod",$null,$View,$null))
{
@{ $Record.GetType().InvokeMember(
"StringData","GetProperty",$null,$Record,1) =
$Record.GetType().InvokeMember(
"StringData","GetProperty",$null,$Record,2)}
}
$View.GetType().InvokeMember("Close","InvokeMethod",$null,$View,$null)

Examples

Now, Why would you want to look at the properties of a MSI package?

Well, say you installed an application package into your Windows Install.wim image. However, you might want to try re-installing the same application package during deploy time. How to ensure that you don’t try to re-run the installation for the same package again if installed.

Well ZTIApplications in MDT can leverage the MSI Product Code. IT will check the registry for the MSI Product Code, and skip over the installation if present.

Just ensure that the product code is set in the application package as the uninstall key name:

See:
http://blogs.technet.com/b/mniehaus/archive/2008/09/25/dynamic-application-detection-with-lite-touch.aspx

Source

https://onedrive.live.com/?cid=5407B03614346A99&id=5407B03614346A99%2110698

Cheers!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s