2020-11-04 15:58:04 +00:00
|
|
|
#[CmdletBinding(SupportsShouldProcess)]param(
|
|
|
|
[CmdletBinding()]param([string[]]$MatchName,[string[]]$OrderBy,[switch]$PassThru,[string[]]$MatchAny)
|
|
|
|
|
2021-05-27 15:48:00 +00:00
|
|
|
$local:containers = [ordered]@{}
|
|
|
|
$(docker ps -q) |
|
2020-11-04 15:58:04 +00:00
|
|
|
ForEach-Object {
|
2021-05-27 15:48:00 +00:00
|
|
|
$local:tmp = docker inspect $_ | ConvertFrom-Json;
|
|
|
|
$local:tmpObj = [PSCustomObject]([ordered]@{
|
|
|
|
Name=$tmp.Name.Substring(1)
|
|
|
|
Project=$tmp.Config.Labels.'com.docker.compose.project'
|
|
|
|
Service=$tmp.Config.Labels.'com.docker.compose.service'
|
|
|
|
Status=$tmp.State.Status
|
|
|
|
Image=$tmp.Config.Image
|
|
|
|
Ports=$(
|
2021-06-24 13:47:51 +00:00
|
|
|
if( $tmp.HostConfig -and $tmp.HostConfig.PortBindings ) {
|
|
|
|
$tmp.HostConfig.PortBindings | Get-Member -type NoteProperty | Select-Object -ExpandProperty Name |
|
|
|
|
ForEach-Object {
|
|
|
|
"$($tmp.HostConfig.PortBindings."$_".HostPort)/$_"
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 15:48:00 +00:00
|
|
|
)
|
|
|
|
Binds= $tmp.HostConfig.Binds
|
|
|
|
raw = $tmp
|
|
|
|
})
|
|
|
|
$tmpObj.PSObject.TypeNames.Insert(0,"DockerContainersOutput")
|
|
|
|
$containers[$tmpObj.Name]=$tmpObj
|
|
|
|
}
|
2020-11-04 15:58:04 +00:00
|
|
|
|
2021-05-27 15:48:00 +00:00
|
|
|
$local:result = $containers.Values | Sort-Object Name
|
2020-11-04 15:58:04 +00:00
|
|
|
if( $MatchName ) {
|
|
|
|
$result = $result | Where-Object Name -match $($MatchName -join '|')
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $MatchAny ) {
|
2021-07-16 13:04:24 +00:00
|
|
|
$result = $result | Where-Object { $_ | Format-Table -Wrap -HideTableHeaders | Out-String | Where-Object { $_ -match $($MatchAny -join '|') } }
|
2020-11-04 15:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $OrderBy ) {
|
|
|
|
$result = $result | Sort-Object $OrderBy
|
|
|
|
}
|
|
|
|
|
2021-05-27 15:48:00 +00:00
|
|
|
#if( $PassThru ) { return $result }
|
|
|
|
$result #| Format-Table -Wrap
|
2020-11-04 15:58:04 +00:00
|
|
|
|