A few dir/ls/Get-ChildItem Powershell commands

Get-ChildItem is aliased as ls/dir (as well as gci), so is used to list files and directories.

Here’s a few useful commands

Find only folders/directories

ls -Directory

Find only files

ls -File

Find files with a given extension

ls -Recurse | where {$_.Name -like "*.bak"}

Only search to a certain depth

The above will recurse over all folders, but we might want to restrict this by a certain depth level, i.e. in this example up to 2 directories deep

ls -Recurse -Depth 2 | where {$_.Name -like "*.bak"}

Finding the directories with files with a given extension

ls -Recurse -Depth 2 | where {$_.Name -like "*.bak"} | select directory -Unique

The use of -Unique ensure we do not have multiple directories with the same path/name (i.e. for each .bak file found within a single directory)