EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Get-ChildItem
 

PowerShell Get-ChildItem

Chirag Nagarekar
Article byChirag Nagarekar
EDUCBA
Reviewed byRavi Rathore

PowerShell Get-ChildItem

Introduction to PowerShell Get-ChildItem

Get-ChildItem in PowerShell works similar to dir command in the windows command prompt. It can be used to retrieve the data from the specified location. In PowerShell subfolders, files or registry are called child items. If you want to retrieve the items from child containers then you need to use –Recurse parameter. Similar to dir /s in cmd.

 

 

Location can be a file system location, such as local directory, shared path directory, registry hive or certificate store. When you use Get-ChildItem for a system drive then it retrieves the directories, sub-directories, and files, but when you use it for directory then it retrieves the sub-directories and files underneath it. Its alias name is gci.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax #1:

Get-ChildItem
[[-Path] <string[]>] [[-Filter] <string>] [-Include <string[]>] [-Exclude <string[]>] [-Recurse] [-Depth <uint32>] [-Force] [-Name] [-Attributes <FlagsExpression[FileAttributes]>] [-FollowSymlink] [-Directory] [-File] [-Hidden] [-ReadOnly] [-System] [<CommonParameters>]

Syntax #2:

Get-ChildItem
[[-Filter] <string>] -LiteralPath <string[]>
[-Include <string[]>] [-Exclude <string[]>] [-Recurse] [-Depth <uint32>] [-Force] [-Name] [-Attributes <FlagsExpression[FileAttributes]>] [-FollowSymlink] [-Directory] [-File] [-Hidden] [-ReadOnly] [-System] [<CommonParameters>]

Parameters of PowerShell Get-ChildItem

Following are the parameters of PowerShell Get-ChildItem explained below:

1) –Attributes <FileAttributes>: This parameter gets files and folders with specified attributes. When you use this parameter, you can specify a complex combination of attributes.

Examples:

  • To get System files that are encrypted.

Get-ChildItem -Attributes System+Encrypted

  • To get non-system files (not Directory) which are encrypted or compressed.

Get-ChildItem -Attributes !Directory+!System+Encrypted, !Directory+!System+Compressed

You cannot use space between an operator and its attributes, but space is permitted before commas. The Attribute parameter supports the following attributes.

Archive Offline
Compressed ReadOnly
Device ReparsePoint
Directory SparseFile
Encrypted System
Hidden Temporary
Normal NotContentIndexed

Following Operators can be used to combine attributes:

! NOT
+ AND
, OR

Following abbreviations are used for attributes:

  • D: Directory
  • H: Hidden
  • R: Read-Only
  • S: System

2) –Directory: When you use -Directory parameter, you will get only directories (folders) as a child item, this will exclude files from being displayed. To exclude directories, use -file attribute. Its alias is “d” or “ad”, depends on file system provider.

3) –File: The file attribute gives an output of only files under that container. To exclude files you need to use -Directory parameter. Its alias is “af”.

4) –Hidden: By default, Get-ChildItem displays non-hidden files and folders. If you want to display all files and folder including hidden ones then use -Force parameter. When you use -Hidden parameter then it will display only hidden files and folders. Its alias name is “h” or “ah”, depends on the file system provider.

5) –Readonly: It will display only read-only files and folders (directories). Its alias name is “ar”.

6) –System: This attribute will display only system files and folders. Its alias name is “as”.

7) –Force: This attribute will provide all files and folders including the hidden files and folders. By default, hidden files and folders are not included. We can also get hidden files and directories with -hidden parameters.

8) –UseTransaction: Includes the command in the active transaction. This parameter is valid when the current transaction is in progress. To learn more about transactions, check help in PowerShell about_Transactions.

9) –Depth: This parameter is used to control the recursion of directories. By default, Get-ChildItem provides you the parent files and folders and when you use recursion it provides all the subdirectories and their contents but when you use the Depth parameter, you can get the exact level of subdirectories and their content.

For example, When you provide Depth level 2, it gets you the contents from their first level subdirectories and second level subdirectories. When you use –Depth parameter –the Recurse parameter is not required. This parameter is introduced in Powershell 5.0.

10) –Exclude: This is a string parameter and it can exclude file, directory, extension, etc when specified after –Exclude from the path. You can use the wildcard characters, for example, *.txt, Test*.

11) –Include: This is a string parameter and when this parameter is used, it displays specific files and folders. For example, if *.txt is included then it will display only text files. You can include more than one choice. For example, *.txt, *.mp4 both can be included separated by comma (,).

12) –Filter: You can also filter the path with -filter parameter. The filter parameter is more efficient than include parameter because it retrieves the object while querying while other parameters retrieve after query. This parameter supports wildcard characters. The filesystem provider is the only PowerShell provider that supports the use of filters.

13) –Path: This parameter specifies the path of one or more locations. You can use wildcard characters with path and if the location not specified, it takes the current location as the default location.

14) –LiteralPath: This parameter specifies the path of one or more locations. Unlike -path parameter, you cannot specify wildcard characters here because this parameter can’t interpret characters as wildcards. If your path includes any escape characters then mark them under a single quote and PowerShell will consider it as a single path.

15) –Name: This parameter retrieves the only name of the items from Get-ChildItem output, not the path of the directory, mode, LastWriteTime, etc.

16) -CommonParameters: Below common parameters are used which are also called advance function’s parameters. Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Properties and Operations Supported by Get-ChildItem

Following are the properties and operations supported by Get-ChildItem Explained below:

1. Properties of Directory

Directory

2. Properties of File

FileInfo

3. Methods of Directory

Powershell Get-childItem 1-3

4. Methods of File

Powershell Get-childItem 1-4

Examples of PowerShell Get-ChildItem

Below are some examples of PowerShell Get-ChildItem:

Example #1 – Parent Files and Folders

The below script will display parent files and folders.

Get-ChildItem -Path D:\Temp

Output:

Powershell Get-childItem 1-5

Example #2 – Recurse Parameter

The below script will display sub files and folders contents but not hidden files.

Get-ChildItem -Path D:\Temp -Recurse

Output:

Recurse parameter

Example #3 – Depth Parameter

The below script will display sub files and folders contents up to 2 levels that are sub-folders and their sub-folders with their contents.

Get-ChildItem -Path D:\Temp -Recurse -Depth 2

Output:

Depth

Example #4 – Hidden Parameter

The below script will display only hidden files from the given path.

Get-ChildItem -Path D:\Temp -Recurse -Hidden

Output:

hidden files

Example #5 – Include Parameter

Below script will include all files with extension *.xml

Get-ChildItem -Path D:\Temp -Recurse -Include *.xml

Output:

Powershell Get-childItem 1-9

Example #6 – Exclude Parameter

The below script will exclude files and folders which start with S.

Get-ChildItem -Path D:\Temp -Exclude S*

Output:

Powershell Get-childItem 1-10

Example #7 – Force Parameter

The below script will display sub-files and folder’s contents and hidden files as well.

Get-ChildItem -Path D:\Temp -Depth 1 -Force

Output:

Powershell Get-childItem 1-11

Example #8 – Attribute Parameter

The below script will exclude directories and check for hidden files. Likewise, you can combine different attributes to get the desired results.

Get-ChildItem d:\Temp -Recurse -Attributes !Directory,!Directory+Hidden

Output:

Powershell Get-childItem 1-12

Example #9 – Name Parameter

The below script will display only the names of the files and folders, excluding other parameters.

Get-ChildItem d:\Temp -Recurse -Attributes !Directory,!Directory+Hidden -Name

Output:

Powershell Get-childItem 1-13

Example #10 – Registry Values

You can also retrieve various registry values as displayed below.

Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE
Get-ChildItem -Path Registry::HKEY_CLASSES_ROOT
Get-ChildItem -Path Registry::HKEY_CURRENT_CONFIG
Get-ChildItem -Path Registry::HKEY_CURRENT_USER
Get-ChildItem -Path Registry::HKEY_USERS
Get-ChildItem -Path Registry::HKEY_PERFORMANCE_DATA

Example #11 – Certificates

To get all the certificates to use below command.

Get-ChildItem -Path Cert:\* -Recurse

Recommended Articles

This is a guide to PowerShell Get-ChildItem. Here we discuss the top 16 parameters, Operations and various examples of PowerShell Get-ChildItem. You may also look at the following articles to learn more –

  1. Parameters of Add-Content in PowerShell
  2. Examples of Get Help in PowerShell
  3. PowerShell vs CMD
  4. Top 10 PowerShell Interview Questions
  5. Complete Guide to PowerShell Format Table
  6. Learn the PowerShell Get-Location

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW