PowerTip: Use PowerShell to Find Folders that Match Pattern


Summary: Learn how to use Windows PowerShell to find folders with names that match a specific pattern.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find the path to folders that have names that match a specific pattern?

Hey, Scripting Guy! Answer Use the Get-ChildItem cmdlet and the –Filter parameter with a pattern that matches the name, and then
           specify the  –Directory parameter. Here is an example that matches folders that have a four-letter name:

Get-ChildItem E:\Data\ScriptingGuys -filter "????" -Directory |

 % { $_.fullname }

Comments (1)

  1. Anonymous says:

    I think this would give back any directory name up to 4 characters. Would you not have to include a check for $_.Name.Length -eq 4?

Skip to main content