Windows: Finding Files with PowerShell

  • When working from the command line in Windows, we often need to find files but doing so can be less than intuitive. The command that we need is the Get-ChildItem command. To be generally useful, we need to use this command with recursion so that it digs into the filesystem. Without recursion it would only find a file in a single folder which we could normally do simply by listing out the folder.

    Here is the standard syntax:

    Get-ChildItem -Path C:\MyFolder\MySubFolder -Filter MyFile.txt -Recurse

    We will normally use all three path, filter and recurse options in any normal file search. As with most of PowerShell, there are a huge number of options and optional approaches to using this command. This is one of the most straightforward and obvious forms.