PowerShell: Get-ComparableVersion
function Get-ComparableVersion {
[CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName="None")]
PARAM(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ParameterSetName="p1")]
[String]
$Version
)
BEGIN {
Write-Verbose $Version
}
PROCESS {
$Version_Sections = $null
$Version_Sections = $Version -split ("\.")
# Validate all sections are integers
foreach ($Version_Section In $Version_Sections) {
if (![int32]::TryParse($Version_Section, [ref]"")) {return}
}
$LongVersion = $Version_Sections[0]
foreach ($SectionIndex in (1..($Version_Sections.Length - 1))) {
Write-Verbose ([int]$Version_Sections[$SectionIndex]).ToString("0" * 11)
$LongVersion += ([int]$Version_Sections[$SectionIndex]).ToString("0" * 11)
}
$LongVersion
}
END {
}
}
Clear-Host
Get-ComparableVersion -Version '15.0.4823.1000'