-
Notifications
You must be signed in to change notification settings - Fork 237
/
Get-NavContainerId.ps1
37 lines (36 loc) · 1.1 KB
/
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
<#
.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-BcContainerId -containerId bcserver
#>
function Get-BcContainerId {
[CmdletBinding()]
Param (
[string] $containerName = $bcContainerHelperConfig.defaultContainerName
)
$id = ""
docker ps --format "{{.ID}}:{{.Names}}" -a --no-trunc | ForEach-Object {
$ps = $_.split(':')
if ($containerName -eq $ps[1]) {
$id = $ps[0]
}
if ($ps[0].StartsWith($containerName)) {
if ($id) {
throw "Unambiguous container ID specified"
}
$id = $ps[0]
}
}
if (!($id)) {
throw "Container $containerName does not exist"
}
$id
}
Set-Alias -Name Get-NavContainerId -Value Get-BcContainerId
Export-ModuleMember -Function Get-BcContainerId -Alias Get-NavContainerId