Skip to content

Instantly share code, notes, and snippets.

@pinecones-sx
Last active March 1, 2017 16:57
Show Gist options
  • Save pinecones-sx/9749b370594eea2254d5fb6eb3cc1caf to your computer and use it in GitHub Desktop.
Save pinecones-sx/9749b370594eea2254d5fb6eb3cc1caf to your computer and use it in GitHub Desktop.
fixed nested if
function Get-VersionAsInt {
param($VersionInfo,[switch]$FileVersion)
$digits = 6
If ($FileVersion){$iVersionNumber = $VersionInfo.FileVersion}
Else{$iVersionNumber = $VersionInfo.ProductVersion}
$rVersionInt = ''
ForEach ($versionPart in ($iVersionNumber -split '\.')){
$lessDigits = $digits - $versionPart.Length
For ($i = 0 ; $i -lt $lessDigits ; $i++){
$versionPart = '0' + $versionPart
}
$rVersionInt = $rVersionInt + [string]$versionPart
}
$rVersionInt = [decimal]($rVersionInt.TrimStart('0'))
Return $rVersionInt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment