I'm trying to use the following code to compare a file's version to a specified version, and tell me which one is higher.
function Get-FileVersionInfo
{
param(
[Parameter(Mandatory=$true)]
[string]$FileName)
if(!(test-path $filename)) {
write-host "File not found"
return $null
}
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo($FileName)
}
$file = Get-FileVersionInfo("C:\program files\internet explorer\iexplore.exe")
if($file.ProductVersion -gt "11.00.9600.17840") {
echo "file is higher version"
}
elseif($file.ProductVersion -eq "11.00.9600.17840") {
echo "file is equal version"
}
else {
echo "file is lower version"
}
echo "Product version is:" $file.ProductVersion
FYI using ProductVersion instead of FileVersion because FileVersion seems to contain extra data sometimes.
It returns "file is a lower version" even though that's the same version that is displayed in Properties.
Do I need to do something else to get it to compare the ProductVersion property to a string?
if($file.ProductVersion -gt [version]"11.00.9600.17840") {