EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Get-ChildItem
Secondary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Get-ChildItem

By Chirag NagarekarChirag Nagarekar

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.

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>]

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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:

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,294 ratings)

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
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
Data Visualization Training (15 Courses, 5+ Projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more