Monday, 9 January 2023

Get-ChildItem - Powershell command to find items in a specified location

The 'Get-ChildItem' cmdlet gets the items in one or more specified locations.

 It can be used to list the files and directories in a particular directory, or to list the registry keys and values in a registry hive.


How to use 'Get-ChildItem' to list the files in the current directory:
                    
Get-ChildItem


We can also specify a different directory to list the files and directories in that directory by using the -Path parameter: 

Get-ChildItem -Path D:\TestDir


To get the list of files with a particular extension, suppose .txt files, using Get-ChildItem Command, it can be used as:

 Get-ChildItem -Filter *.txt


We can find more about Get-ChildItem command and its usage by using:

                    Get-Help Get-ChildItem 

 Get-ChildItem [[-Filter] <System.String>] [-Attributes {Archive | Compressed | Device | Directory | Encrypted | Hidden | IntegrityStream | Normal | NoScrubData | NotContentIndexed |Offline | ReadOnly | ReparsePoint | SparseFile | System | Temporary}] [-Depth <System.UInt32>] [-Directory] [-Exclude <System.String[]>] [-File] [-Force] [-Hidden] [-Include     <System.String[]>] -LiteralPath <System.String[]> [-Name] [-ReadOnly] [-Recurse] [-System] [-UseTransaction] [<CommonParameters>]


    Get-ChildItem [[-Path] <System.String[]>] [[-Filter] <System.String>] [-Attributes {Archive | Compressed | Device | Directory | Encrypted | Hidden | IntegrityStream | Normal | NoScrubData | NotContentIndexed | Offline | ReadOnly | ReparsePoint | SparseFile | System | Temporary}] [-Depth <System.UInt32>] [-Directory] [-Exclude <System.String[]>] [-File] [-Force] [-Hidden] [-Include <System.String[]>] [-Name] [-ReadOnly] [-Recurse] [-System] [-UseTransaction] [<CommonParameters>]