Yet another file system task: list all *.log files in a folder structure, but only to a maximum depth of 2 folder structures:

Get-ChildItem -Path c:\windows -Filter *.log -Recurse -Depth 2 -File -Force -ErrorAction SilentlyContinue |
  Select-Object -ExpandProperty FullName

Fortunately, PowerShell 5 added the helpful -Depth parameter to Get-ChildItem.

Twitter This Tip! ReTweet this Tip!

Anonymous