2

Given:
PowerShell 5.1

Can someone help me extract metadata from an msi file?

enter image description here

I've tried the following, but no comments property.

$filePath = "C:\Users\user1\source\repos\PRACTICE\WpfApp1\SetupProject1\bin\Debug\SetupProject1.msi"
$fileProperties = Get-ItemProperty -Path $filePath
$fileProperties | Format-List *

2 Answers 2

2

You can try using Shell.Application COM object to extract the metadata, I don't know of a way to extract just Comments, but there is a way to extract all the metadata from it into an ordered dictionary.

# using PowerShell msi for the example
$path = 'path\to\PowerShell-7.5.0-win-x86.msi'
$shell = New-Object -ComObject Shell.Application
$dir = $shell.NameSpace([System.IO.Path]::GetDirectoryName($path))
$item = $dir.ParseName([System.IO.Path]::GetFileName($path))
$metadata = [ordered]@{}

for ($id = $nullCounter = 0; $nullCounter -lt 10; $id++) {
    $key = $dir.GetDetailsOf($null, $id)
    $value = $dir.GetDetailsOf($item, $id)

    if ($key -and $value) {
        $metadata[$key] = $value
        $nullCounter = 0
        continue
    }

    if ($id -lt 320) { continue }
    $nullCounter++
}

Then from here you should have all the file metadata in $metadata, and assuming it had a Comments key, you could do:

$metadata['Name']     # PowerShell-7.5.0-win-x86.msi
$metadata['Comments'] # PowerShell for every system
$metadata['Title']    # Installation Database
$metadata['Subject']  # PowerShell package
$metadata['Authors']  # Microsoft Corporation
Sign up to request clarification or add additional context in comments.

Comments

0

To complement Santiago's helpful answer with a way to directly extract a specific extended property:

  • Using the code and results from the bottom part of this answer, we can infer that the Comments property has an index of 24 that can be passed as the 2nd argument to the .GetDetailsOf() method:
# Be sure to specify a *full* path.
$filePath = "C:\Users\user1\source\repos\PRACTICE\WpfApp1\SetupProject1\bin\Debug\SetupProject1.msi"

# Parse the file using the Windows shell APIs to gain access to the extended properties.
$folder = (New-Object -ComObject Shell.Application).NameSpace((Split-Path -Parent $filePath))
$file = $folder.ParseName((Split-Path -Leaf $filePath))

# Extract the "Comments" property value via index 24
$folder.GetDetailsOf($file, 24)
# Be sure to specify a *full* path.
$filePath = "C:\Users\user1\source\repos\PRACTICE\WpfApp1\SetupProject1\bin\Debug\SetupProject1.msi"

# Parse the file using the Windows shell APIs to gain access to the extended properties.
$folder = (New-Object -ComObject Shell.Application).NameSpace((Split-Path -Parent $filePath))
$file = $folder.ParseName((Split-Path -Leaf $filePath))

# Extract the "Comments" property value via the property's well-known name.
$file.ExtendedProperty('System.Comment')

[1] See the Windows Property help topic, which offers a categorized list of well-known properties. Those not specific to a particular file type are listed in the Core category, System.Comment among them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.