Get the items and child items in a folder or registry key. (dir / ls / gci)
Syntax
Get-ChildItem [[[-path]| [-literalPath] ]string[]] [[-filter] string]
[-include string[]] [-exclude string[]] [-name] [-recurse]
[-force] [CommonParameters]
Key
-path string
The paths to the items from which content is to be retrieved.
Wildcards are permitted.
-literalPath string
Like Path above, only the value is used exactly as typed.
No characters are interpreted as wildcards. If the path includes any
escape characters then enclose the path in single quotation marks.
-include string
Include only the specified items from the Path. e.g. "May*"
-exclude string
Omit the specified items from the Path e.g. "*SS64*"
This parameter does not work properly in this cmdlet.
-filter string
A filter in the provider's format or language.
The exact syntax of the filter (wildcard support etc) depends on the provider.
Filters are more efficient than -include/-exclude, because the provider
applies the filter when retrieving the objects, rather than having
PowerShell filter the objects after they are retrieved.
-name
Retrieve only the names of the items.
This is useful when piping the names of the child items to another command.
-recurse
Get the items plus all child items of the location(s).
Only for paths that point to a container such as C:\Windows or C:\Windows\*
A path such as *.txt will not have any child items.
-force
Override restrictions that prevent the command from succeeding, apart
from security settings. e.g. Force will create file path directories
or override a files read-only attribute, but will not change file permissions.
-codeSigningCert
Retrieve only certificates that have code signing authority.
Valid only when using the Windows PowerShell Certificate provider.
For more info, type "get-help about_provider" and "get-help about_signing".
CommonParameters:
-Verbose, -Debug,-ErrorAction,-ErrorVariable, -OutVariable.
When listing files and sub-directories, get-childitem will return the mode (attributes), last write time, file size (length), and the filename.
Valid modes (attributes) are: d (directory), a (archive), r (read-only), h (hidden), and s (system).
The default path is the current directory ' . ' to specify all the items in the current directory use *
Examples
Get the child items in the current location:
PS C:\>get-childitem
List all the .XLS files in C:\Work and all sub-folders:
PS C:\>get-childitem C:\Work\ -Include *.xls -Recurse
List all the files owned by BillG:
PS C:\>get-childitem C:\Work\ -recurse | get-acl | where {$_.Owner -match "BillG"}
Measure the size of a folder:
Get-ChildItem C:\Work\ -Recurse -Force | Measure-Object -property length -sum
Get all the certificates in the certificate store that have a code-signing authority:
PS C:\>get-childitem cert:\. -recurse -codesigningcert
You can also run gci against a file share on a remote machine using a UNC path.
"Rarely is the question asked: Is our children learning?" - George W. Bush
Related Powershell Commands:
Get-Item - Get a file object or get a registry (or other namespace) object
Get-Alias - Return alias names for Cmdlets
Get-Location - Display the current location
Get-Process - Get a list of processes on a machine
Join-Path -resolve - Retrieve the full pathnames.
get-help - about_namespace