How to use the wildcard character (*) in Get-ChildItem in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

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
raja
Published on 23-Jan-2020 12:17:45
Advertisements