- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- How to exclude specific extension in Get-ChildItem in PowerShell?
- How to search for a specific extension using Get-ChildItem in PowerShell?
- How to use Depth pararmeter in Get-ChildItem PowerShell?
- How to exclude specific file names using Get-ChildItem in PowerShell?
- How to retrieve specific file(s) information using Get-ChildItem in PowerShell?
- How to use the wildcard character (*) in Get-ChildItem in PowerShell?
- How to use the -recursive parameter in Get-ChildItem using PowerShell?
- How to control recursion in Get-ChildItem in PowerShell?
- How to get the readonly files using Get-ChildItem in PowerShell?
- How to copy files with the specific extension in PowerShell?
- How to get the system files using the Get-ChildItem in PowerShell?
- How to get the file extension using PowerShell?
- How to copy files of the specific extension using PowerShell?
- What is the use of -Force parameter in Get-ChildItem in PowerShell?
- How to list the subfolder contents using Get-ChildItem using PowerShell?

Advertisements