How to search for files using the wildcard character (*) in PowerShell?


You can also search for files with a specific name or using the wildcard (*) character.

Command

Below command will search for the files (including hidden files) starting with “Bac”.

Get-ChildItem D:\Temp -Recurse -Force -Include Bac*

Output

PS C:\WINDOWS\system32> Get-ChildItem D:\Temp -Recurse -Force -Include Bac*
    Directory: D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9}
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       24-11-2018     11:34           6215 Backup.xml

Command

When you use the wildcard character (*) at both the ends, file name containing that string will be displayed. For example, the below command will display all the files which contain the word “tmp”.

Get-ChildItem D:\Temp\ -Recurse -Force -Include *tmp*

Output

PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Recurse -Force -Include *tmp*
    Directory: D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9}\DomainSysvol\GPO\Machine\microsoft\windows
    nt\SecEdit
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       24-11-2018     11:34          16028 GptTmpl.inf

Updated on: 23-Jan-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements