Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function ConvertFrom-DockerPS {
Parses docker ps output to make it more readable
Pipe the results of Docker ps to this function and get the results in a nice, more powershelly format
docker ps | ConvertFrom-DockerPS | select names, image, "container id", created # Get all running containers
docker ps -a | ConvertFrom-DockerPS | where {$_.status -like "exited*"} | docker # Get all closed containers
docker ps -a | ConvertFrom-DockerPS | where {$_.status -like "exited*"} | foreach { docker rm $_.'CONTAINER ID' } # remove all stopped containers
The core of the code was taken from so
credits go to reddit user /u/Lee_Dailey (, a great contributor on the powershell subreddit [grin]
I've also (forcefully) learned the how's and why's of using advanced functions, and the massive value of the ISE (which i will never use again, heh)
Thank you fellow admin for reading this ramblings, and party on!
#Declare the $final helper object
$InStuff = $adentro.Split("`n").Trim("`r")
$OutStuff = $InStuff -replace '\s{23,}', ',,' -replace '\s{2,}', ','
#Added this to mitigate an issue with formatting on the ugly header
if ($OutStuff -like "*IMAGE,COMMAND,*") { $OutStuff= $OutStuff.replace(',,',',')}
#Convert it all to CSV and send it back
$final | ConvertFrom-Csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment