

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Depth pararmeter in Get-ChildItem PowerShell?
When –Depth parameter is used along with Get-ChildItem, it controls the recursion of displaying the subfolders and their contents. For example, if –Depth parameter is set to 1 then it will display only the content of the parent folder and immediate subfolders but not the subfolders of the subfolders.
Command
When you specify –Depth parameter, no need to add –Recursion parameter. It will automatically set the depth level.
Get-ChildItem D:\Temp\ -Depth 1
Output
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Depth 1 Directory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 13-12-2019 09:52 GPO_backup d----- 24-11-2018 11:31 LGPO -a---- 07-05-2018 23:00 301 cars.xml -a---- 29-12-2017 15:16 4526 healthcheck.html -a---- 29-12-2017 15:16 4526 healthcheck1.html -a---- 08-12-2017 10:24 48362 servicereport.html -a---- 08-12-2017 10:24 48362 servicereport1.html -a---- 08-12-2017 10:16 393 style.css -a---- 08-12-2017 11:29 7974 Test.xlsx -a---- 25-10-2017 08:13 104 testcsv.csv -a---- 12-12-2017 23:04 1034 testhtmoutput.html Directory: D:\Temp\GPO_backup Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 24-11-2018 11:34 {C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9} Directory: D:\Temp\LGPO Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 01-06-2017 03:22 410088 LGPO.exe -a---- 01-06-2017 02:25 638115 LGPO.pdf
In the above example, -Depth value is set to 1, so it displays only its subfolders (D:\Temp\LGPO, D:\Temp\GPO_Backup) and their contents.
When you set the –Depth value to 2, the output will be.
Output
Directory: D:\Temp\GPO_backup Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 24-11-2018 11:34 {C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9} Directory: D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9} Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 24-11-2018 11:34 DomainSysvol -a---- 24-11-2018 11:34 6215 Backup.xml -a---- 24-11-2018 11:34 602 Bkupinfo.xml Directory: D:\Temp\LGPO Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 01-06-2017 03:22 410088 LGPO.exe -a---- 01-06-2017 02:25 638115 LGPO.pdf
As you can see in above example, additional level (D:\Temp\GPO_backup\{C9C3DB4C-2E51-4201-B3C3-7C0F1ACECBE9}) has been added.
- Related Questions & Answers
- How to use the wildcard character (*) in Get-ChildItem in PowerShell?
- How to use the -recursive parameter in Get-ChildItem using PowerShell?
- How to use Get-ChildItem in PowerShell to filter a specific extension?
- How to control recursion in Get-ChildItem in PowerShell?
- How to get the readonly files using Get-ChildItem in PowerShell?
- What is Get-ChildItem cmdlet in PowerShell?
- How to exclude specific extension in Get-ChildItem in PowerShell?
- What is the use of -Force parameter in Get-ChildItem in PowerShell?
- How to get the system files using the Get-ChildItem in PowerShell?
- How to exclude specific file names using Get-ChildItem in PowerShell?
- How to list the subfolder contents using Get-ChildItem using PowerShell?
- Which methods are supported by Get-ChildItem in PowerShell?
- How to retrieve specific file(s) information using Get-ChildItem in PowerShell?
- How to search for a specific extension using Get-ChildItem in PowerShell?
- How to get only folders but not the files in the Get-ChildItem in PowerShell?
Advertisements