You are currently viewing PowerShell Get-ChildItem Cmdlet

PowerShell Get-ChildItem Cmdlet

PowerShell Get-ChildItem Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Set-ItemProperty cmdlet in PowerShell.

In this blog post, we will discuss Get-ChildItem cmdlet in PowerShell. You can use Get-ChildItem cmdlet to list the content of a directory or registry hive. Get-ChildItem supports arguments like ‘depth’ and ‘Attributes’ which allows you to control the amount and type of data that you want to get. Get-ChildItem cmdlet doesn’t display empty directories.

By default, Get-ChildItem lists the mode (Attributes), LastWriteTime, file size (Length), and the Name of the item. The letters in the Mode property can be interpreted as follows:

  • l (link)
  • d (directory)
  • a (archive)
  • r (read-only)
  • h (hidden)
  • s (system)

Get-ChildItem Cmdlet Syntax:

Get-ChildItem Cmdlet Argument List:

  • Attributes: Gets files and folders with the specified attributes. This parameter supports all attributes and lets you specify complex combinations of attributes. The Attributes parameter supports the following properties:
    • Archive: This file is marked to be included in the incremental backup operation.
    • Compressed: The file is compressed.
    • Device: Reserved for future use.
    • Directory: The file is a directory.
    • Encrypted: The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and directories.
    • Hidden: The file is hidden, and thus is not included in an ordinary directory listing.
    • IntegrityStream: The file or directory includes data integrity support.
    • Normal: The file is a standard file that has no special attributes.
    • NoScrubData: The file or directory is excluded from the data integrity scan.
    • NotContentIndexed: The file will not be indexed by the operating system’s content indexing service.
    • Offline: The file is offline. The data of the file is not immediately available.
    • ReadOnly: The file is read-only.
    • ReparsePoint: The file contains a reparse point, which is a block of user-defined data associated with a file or a directory.
    • SparseFile: The file is a sparse file. Sparse files are typically large files whose data consists of mostly zeros.
    • System: The file is a system file. That is, the file is part of the operating system or is used exclusively by the operating system.
    • Temporary: The file is temporary.
  • Depth: This parameter was added in PowerShell 5.0 and enables you to control the depth of recursion.
  • Directory: To get a list of directories, use the Directory parameter or the Attributes parameter with the Directory property.
  • Exclude: Specifies, as a string array, a property or property that this cmdlet excludes from the operation. The value of this parameter qualifies the Path parameter.
  • File: To get a list of files, use the File parameter. You can use the Recurse parameter with File.
  • Filter: Specifies a filter to qualify the Path parameter.
  • Force: Allows the cmdlet to get items that otherwise can’t be accessed by the user, such as hidden or system files.
  • Hidden: To get only hidden items, use the Hidden parameter or the Attributes parameter with the Hidden property.
  • Include: Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value of this parameter qualifies the Path parameter.
  • LiteralPath: Specifies a path to one or more locations. The value of LiteralPath is used exactly as it’s typed. No characters are interpreted as wildcards.
  • Name: Gets only the names of the items in the location. The output is a string object that can be sent down the pipeline to other commands.
  • Path: Specifies a path to one or more locations. Wildcards are accepted.
  • ReadOnly: To get only read-only items, use the ReadOnly parameter or the Attributes parameter ReadOnly property.
  • Recurse: Gets the items in the specified locations and in all child items of the locations.
  • System: Gets only system files and directories.
  • UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.

PowerShell Get-ChildItem Cmdlet:

List Contents Of A Directory In PowerShell:

List Only Directories In PowerShell:

List Only Files In PowerShell:

List Only Specific Types Of Files Or Files Having Specific Extension In PowerShell:

List All The Files And Directories Up To A Certain Depth In PowerShell:

Get All The Sub Keys Under A Registry Key In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss Get-Location cmdlet in PowerShell.

To Set more details on PowerShell, kindly follow below official documentation


Leave a Reply