Using PowerShell to Find Outdated Ubuntu Containers
Posted on April 30, 2025 by Michael Keane GallowayWith Ubuntu 20.04 LTS’s sunset on the horizon, my manager forwarded an email about the need to update all of our Docker images to version 22.04. He sent it out as an FYI, but I took a moment to context switch towards answering this question because I thought that I could figure this out quickly using a one-liner in PowerShell.
With a little bit of experimentation, I came up with the following:
-ChildItems -recursive -pattern *Dockerfile* .
Get| % { SelectString -pattern 'focal' -file $_.FullName} \
- Since I keep my code repositories fairly organized, I can use
Get-ChildItems
recursively from myrepos
directory (which was my current directory when I ran this script). - I then fed in a file pattern to select for any filename containing
Dockerfile
. That way we could scan through for code repositories with different Docker files for specific purposes. - I pipe the results of recursively navigating my file system to
SelectString
, which acts likegrep
taking a pattern and checking to see if the file contains the string'focal'
.
The script turned up 2 file hits. Both were from repositories for other teams that I had cloned out of curiosity. All of our code had moved off of focal. I did a quick double check, and verified that our efforts to upgrade from DotNet 6.0 to 8.0 led us to upgrade to the next Ubuntu LTS.
Much like other articles that I have written about my PowerShell scripts, I hope this serves as a good example of how you can quickly solve problems with shell scripting. It’s a good tool to have in your metaphorical toolbox. Whether it’s BASH or PowerShell, a software engineer needs these tools to quickly analyze files and figure out what they can about their systems.