ContainerInfo/Get-NavContainerId.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
31
32
33
34
35
36
37
38
<#
 .Synopsis
  Get the Id of a NAV/BC Container
 .Description
  Returns the Id of a Container based on the container name
  The Id returned is the full 64 digit container Id and the name must match
 .Parameter containerName
  Name of the container for which you want the Id
 .Example
  Get-NavContainerId -containerId navserver
#>

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

    Process {
        $name = Get-NavContainerName $containerName
        if ($name) { $containerName = $name }

        $id = ""
        docker ps --format "{{.ID}}:{{.Names}}" -a --no-trunc | ForEach-Object {
            $ps = $_.split(':')
            if ($containerName -eq $ps[1]) {
                $id = $ps[0]
            }
        }
        if (!($id)) {
            throw "Container $containerName does not exist"
        }
        $id
    }
}
Set-Alias -Name Get-BCContainerId -Value Get-NavContainerId
Export-ModuleMember -Function Get-NavContainerId -Alias Get-BCContainerId