Skip to content

Instantly share code, notes, and snippets.

@edwinheij
Created March 8, 2017 10:01
Show Gist options
  • Save edwinheij/369b15e0444a1dbbe177da2b5f72d4db to your computer and use it in GitHub Desktop.
Save edwinheij/369b15e0444a1dbbe177da2b5f72d4db to your computer and use it in GitHub Desktop.
Powershell: Version compare
function getVersionFromFile($filepath) {
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo($filepath)
}
function versionCompare($filepathReference, $filepathDifference) {
$versionReference = getVersionFromFile $filepathReference
$versionDifference = getVersionFromFile $filepathDifference
#$versionReference | fl
#$versionDifference
return Compare-Object -ReferenceObject $versionReference -DifferenceObject $versionDifference -Property FileVersionRaw
#return Compare-Object $versionReference $versionDifference
}
$filepath1 = "C:\Program Files\Git\git-cmd.exe"
$filepath2 = "$Env:USERPROFILE\Downloads\Git-2.8.3-64-bit.exe"
#$filepath2 = "$Env:USERPROFILE\Downloads\Git-2.6.0-32-bit.exe"
try {
$compare = versionCompare $filepath1 $filepath2
if ($compare.count -gt 0) {
throw error
}
write-host update the system
} catch {
Write-Host "Geen versie kunnen vinden van 1 van de bestanden"
}
break
$filepath = "C:\Program Files\Git\git-cmd.exe"
versionCompare $filepath
break
$a = getVersionFromFile($filepath)
#$a.ToString()
$filepath = "$Env:USERPROFILE\Downloads\Git-2.8.3-64-bit.exe"
$filepath = "$Env:USERPROFILE\Downloads\Git-2.6.0-32-bit.exe"
$b = getVersionFromFile($filepath)
#$b.ToString()
$compare = Compare-Object -ReferenceObject $b -DifferenceObject $a
$compare.count
if ($compare.count) {
write-host not ok
} else {
write-host ok
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment