ContainerInfo/Get-NavContainerCountry.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<#
 .Synopsis
  Get the country version from a NAV/BC Ccontainer or a NAV/BC Container image
 .Description
  Returns the country version (localization) for the version of NAV or Business Central in the Container or ContainerImage
 .Parameter containerOrImageName
  Name of the container or container image for which you want to get the country version
 .Example
  Get-NavContainerCountry -containerOrImageName navserver
 .Example
  Get-NavContainerCountry -containerOrImageName mcr.microsoft.com/businesscentral/onprem:dk
#>

function Get-NavContainerCountry {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$true)]
        [string] $containerOrImageName
    )

    Process {
        $inspect = docker inspect $containerOrImageName | ConvertFrom-Json
        if ($inspect.Config.Labels.psobject.Properties.Match('nav').Count -eq 0) {
            throw "Container $containerOrImageName is not a NAV/BC container"
        }
        return "$($inspect.Config.Labels.country)"
    }
}
Set-Alias -Name Get-BCContainerCountry -Value Get-NavContainerCountry
Export-ModuleMember -Function Get-NavContainerCountry -Alias Get-BCContainerCountry