Public/Get-FirebirdVersion.ps1
|
function Get-FirebirdVersion { <# .SYNOPSIS Parses a Firebird version string into a structured object. .DESCRIPTION Parses version strings produced by Firebird tools (gstat -z, isql -z, etc.) into a structured object with platform, version, build number, and server name. Accepts version strings in the format: - 'LI-V5.0.3.1683 Firebird 5.0' - 'WI-V4.0.5.3140 Firebird 4.0' - 'LI-V3.0.12.33787 Firebird 3.0' - 'WI-T6.0.0.1887 Firebird 6.0 2e18929' (snapshot/test builds) Also accepts just the version prefix (e.g. 'LI-V5.0.3.1683'). The 'V' prefix indicates a release build; 'T' indicates a test/snapshot build. .PARAMETER VersionString The Firebird version string to parse. Can be piped. .EXAMPLE Get-FirebirdVersion 'LI-V5.0.3.1683 Firebird 5.0' .EXAMPLE 'WI-V4.0.5.3140 Firebird 4.0' | Get-FirebirdVersion .OUTPUTS PSCustomObject with Platform, Version, Build, and ServerName properties. #> [CmdletBinding()] [OutputType([PSCustomObject])] Param( [Parameter(Mandatory, ValueFromPipeline)] [string]$VersionString ) process { if ($VersionString -notmatch '^(LI|WI)-([VT])(\d+\.\d+\.\d+)\.(\d+)(.*)$') { throw "Cannot parse Firebird version string: '$VersionString'" } $platform = switch ($Matches[1]) { 'LI' { 'Linux' } 'WI' { 'Windows' } } $isSnapshot = $Matches[2] -eq 'T' $version = [semver]$Matches[3] $build = [int]$Matches[4] $remainder = $Matches[5].Trim() $serverName = if ($remainder -ne '') { $remainder } else { $null } [PSCustomObject]@{ Platform = $platform Version = $version Build = $build ServerName = $serverName IsSnapshot = $isSnapshot } } } |