Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to use Get-ChildItem in PowerShell to filter a specific extension?
To get the output of the get-childitem with a specific extension, we need to use –includeparameter.
Example
In the below example, we will use the below script to get only .xml files.
Get-ChildItem D:\Temp\ -Recurse -Include *.xml
Output
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Recurse -Include *.xml
Directory: D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9}
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 24-11-2018 11:34 6215 Backup.xml
-a---- 24-11-2018 11:34 602 Bkupinfo.xml
Directory: D:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 07-05-2018 23:00 301 cars.xml
You can filter multiple extensions with include parameter and for that, you need to add a comma (,) between extensions.
Example
For example, we will get the output here with file extensions xml and csv.
Get-ChildItem D:\Temp\ -Recurse -Include *.xml, *.csv
Output
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Recurse -Include *.xml, *.csv
Directory: D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9}\DomainSysvol\GPO\Machine\microsoft\windows
nt\Audit
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 24-11-2018 11:34 6234 audit.csv
Directory: D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9}
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 24-11-2018 11:34 6215 Backup.xml
-a---- 24-11-2018 11:34 602 Bkupinfo.xml
Directory: D:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 07-05-2018 23:00 301 cars.xml
-a---- 25-10-2017 08:13 104 testcsv.csv Advertisements
