Skip to content

Instantly share code, notes, and snippets.

@techdecline
Created September 29, 2020 08:22
Show Gist options
  • Select an option

  • Save techdecline/2564dbbdd392f1bc3c4d0c003708a4fd to your computer and use it in GitHub Desktop.

Select an option

Save techdecline/2564dbbdd392f1bc3c4d0c003708a4fd to your computer and use it in GitHub Desktop.
function Get-DockerInfo {
$rtnObj = New-Object PSCustomObject
if (Get-Command "docker" -ErrorAction SilentlyContinue) {
$dockerArr = (docker version 2>0) -split '\n' | Select-Object -First 2 | ForEach-Object {($_ -replace "^.*:").trim()}
foreach ($dockerProp in $dockerArr) {
switch -regex ($dockerProp) {
"^Docker.*" {
$rtnObj | Add-Member -MemberType NoteProperty -Name "DockerName" -Value $dockerProp
}
"^\d{2}\.\d{2}\.\d{2}" {
$rtnObj | Add-Member -MemberType NoteProperty -Name "DockerVersion" -Value $dockerProp
}
}
}
}
else {
return $null
}
return $rtnObj
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment