Functions/Get-BcVersion.ps1
<#
.Synopsis Returns the Business Central Version, VersionNumber, VersionFolder and ProductAbb. .DESCRIPTION Returns the Business Central Version, VersionNumber, VersionFolder and ProductAbb in an hashtable. Returns $false if NavVersion is not valid. Usefull to get the version name (example: nav2017) corresponding to the VersionFolder code (example: 100), or the other way around. .EXAMPLE $BcVersion = Get-BcVersion -BcVersion bc21 $BcVersion.Version # is 'bc21' $BcVersion.VersionFolder # is '100' $BcVersion.VersionNumber # is '21 ' $BcVersion.ProductAbb # is 'BC' .EXAMPLE $BcVersion = Get-BcVersion -VersionFolder '100' $BcVersion.Version # is 'nav2017' $BcVersion.VersionFolder # is '100' $BcVersion.Version # is '2017' $BcVersion.ProductAbb # is 'NAV' .EXAMPLE $BcVersion = Get-BcVersion -BcVersion 'nav2013r2' $BcVersion.Version # is '2013R2' $BcVersion.VersionFolder # is '71' $BcVersion.ProductAbb # is 'NAV' .PARAMETER BcVersion The BcVersion, example: 'bc21', 'bc18', 'bc17', 'nav2017', 'nav2013R2' .PARAMETER VersionFolder The Version Folder, example: '210', '180', '170', '100', '71' #> function Get-BcVersion { [CmdletBinding(DefaultParameterSetName='BcVersion')] [OutputType([hashtable])] Param ( [ValidatePattern('[a-zA-Z]+[\da-zA-Z]+')] [Parameter(Mandatory=$true, ParameterSetName = 'BcVersion')] [String] $BcVersion, [Parameter(Mandatory=$true, ParameterSetName = 'VersionFolder')] [String] $VersionFolder ) [hashtable] $Version = [ordered] @{ Version = ''; VersionNumber = ''; VersionFolder = ''; ProductAbb = '';} # If the version is Business Central if ($VersionFolder -and [int] $VersionFolder -gt 110 -or ($BcVersion -match 'bc*')){ $Version.ProductAbb = 'BC' if($VersionFolder -and ($VersionFolder.Length -eq 3)){ # Example $Version.VersionFolder = $VersionFolder # 210 $Version.VersionNumber = [string] $Version.VersionFolder.SubString(0,2) # 21 $Version.Version = $Version.ProductAbb + $Version.VersionNumber # bc21 return $Version } $match = $BcVersion | Select-String -Pattern '^[\D]{2}([\d]{2})$' if(-not $match){ return $false } $Version.VersionNumber = [int] $match.Matches[0].groups[1].Value # 21 $Version.VersionFolder = ([int] $Version.VersionNumber * 10 ).ToString() # 210 $Version.Version = $BcVersion # bc21 return $Version } # Dynamics NAV versions if ($BcVersion -eq 'nav2018' -or $VersionFolder -eq '110') { $Version.Version = 'nav2018' $Version.VersionNumber = '2018' $Version.VersionFolder = '110' $Version.ProductAbb = 'NAV' } if ($BcVersion -eq 'nav2017' -or $VersionFolder -eq '100') { $Version.Version = 'nav2017' $Version.VersionNumber = '2017' $Version.VersionFolder = '100' $Version.ProductAbb = 'NAV' } if ($BcVersion -eq 'nav2016' -or $VersionFolder -eq '90') { $Version.Version = 'nav2016' $Version.VersionNumber = '2016' $Version.VersionFolder = '90' $Version.ProductAbb = 'NAV' } if ($BcVersion -eq 'nav2015' -or $VersionFolder -eq '80') { $Version.Version = 'nav2015' $Version.VersionNumber = '2015' $Version.VersionFolder = '80' $Version.ProductAbb = 'NAV' } if ($BcVersion -like '*2013R2' -or $VersionFolder -eq '71') { $Version.Version = 'nav2013R2' $Version.VersionNumber = '2013R2' $Version.VersionFolder = '71' $Version.ProductAbb = 'NAV' } if(-not $Version.Version){ return $false } return $Version } Export-ModuleMember -Function Get-BcVersion |