When I initially looked into this problem area, I found that using simple commands like (Get-Item -Path "C:\path\to\file.exe").VersionInfo.ProductVersion
— as suggested in the answers of this SO question — didn't work reliably across all executables (empty return value). I also noticed that Explorer does reliably display the values in a given executable's Properties sheet, so I decided to construct a Powershell function to mimic what Explorer (presumbaly) does to retrieve the properties.
Here's a Powershell function to retrieve all extended properties, including Product Version.
function Get-AllExtendedProperties {
param (
[string]$FilePath
)
If (-not $FilePath) {
Throw "Error: missing `$FilePath parameter"
}
$file = Get-Item $FilePath
If ($file -and $file.Exists) {
$parentFolder = Split-Path $file.FullName -Parent
$shell = New-Object -ComObject Shell.Application
$folder = $shell.Namespace($parentFolder)
$fileItem = $folder.ParseName($file.Name)
# Get all extended properties
$extendedProperties = @{}
For ($i = 0; $i -lt 300; $i++) {
$propertyValue = $folder.GetDetailsOf($fileItem, $i)
if ($propertyValue) {
$propertyName = $folder.GetDetailsOf($folder.Items, $i)
$extendedProperties[$propertyName] = $propertyValue
}
}
# Sort the hashtable by property name
$sortedExtendedProperties = $extendedProperties.GetEnumerator() | Sort-Object Name | ForEach-Object { $_.Key = $_.Key.Trim(); $_ }
Write-Output $sortedExtendedProperties
} Else {
Throw "Error: missing file"
}
}
Usage
The simplest way to use this function is to copy/paste it into a Powershell window and press Return ↵. Then you can use it like this:
Get-AllExtendedProperties -FilePath "C:\path\to\file.exe"
If you want to get a specific property's value, such as the Product Version, use it like this:
Get-AllExtendedProperties -FilePath "C:\path\to\file.exe" | Where-Object {$_.Name -eq 'Product Version'} | Select-Object -ExpandProperty Value