Public/Get-DockerInfo.ps1
<#
.SYNOPSIS Gets info about the Docker-For-Windows Docker Server and Client on a Windows host. This is mainly used to determine if the Docker Server is running in Windows Container mode or Linux Container mode. .DESCRIPTION See .SYNOPSIS .EXAMPLE # Open an elevated PowerShell Session, import the module, and - PS C:\Users\zeroadmin> Get-DockerInfo #> function Get-DockerInfo { $DockerVersionInfo = docker version [System.Collections.ArrayList]$DockerClientInfo = @() [System.Collections.ArrayList]$DockerServerInfo = @() foreach ($line in $DockerVersionInfo) { if ($line -match "^Client") { $ClientOrServer = "Client" } if ($line -match "^Server") { $ClientOrServer = "Server" } if (![string]::IsNullOrEmpty($line)) { if ($ClientOrServer -eq "Client" -and $line -notmatch "^Client") { $null = $DockerClientInfo.Add($line.Trim()) } if ($ClientOrServer -eq "Server" -and $line -notmatch "^Server") { $null = $DockerServerInfo.Add($line.Trim()) } } } [pscustomobject]$DockerClientPSObject = @{} [pscustomobject]$DockerServerPSObject = @{} foreach ($Property in $DockerClientInfo) { $KeyValuePrep = $Property -split ":[\s]+" $key = $KeyValuePrep[0].Trim() $value = $KeyValuePrep[1].Trim() $null = $DockerClientPSObject.Add($key,$value) } foreach ($Property in $DockerServerInfo) { if ([bool]$($Property -match ":[\s]+")) { $KeyValuePrep = $Property -split ":[\s]+" } elseif ([bool]$($Property -match ":")) { $KeyValuePrep = $Property -split ":" } $key = $KeyValuePrep[0].Trim() if ($KeyValuePrep[1] -ne $null) { $value = $KeyValuePrep[1].Trim() } $null = $DockerServerPSObject.Add($key,$value) } [pscustomobject]@{ DockerServerInfo = $DockerServerPSObject DockerClientInfo = $DockerClientPSObject } } |