Click to Rate and Give Feedback
TechNet
TechNet Library
Scripting
Windows PowerShell
 Get-ChildItem
Get-ChildItem

Gets the items and child items in one or more specified locations.

Syntax

Get-ChildItem [[-path] <string[]>] [[-filter] <string>] [-include <string[>] [-exclude <string[]>] [-recurse] [-force] [-name] [<CommonParameters>]

Get-ChildItem [-literalPath] <string[]> [[-filter] <string>] [-include <string[]>] [-exclude <string[]>] [-recurse] [-force] [-name] [<CommonParametes>].

Detailed Description

The Get-Childitem cmdlet gets the items in one or more specified locations. A location can be a file system location, such as a directory, or a location exposed by another provider, such as a registry hive or a certificate store.

If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers.

Parameters

-path <string[]>

Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).

Required?

false

Position?

1

Default Value

<NOTE: if not specified uses Current location>

Accept Pipeline Input?

true <ByValue, ByPropertyName>

Accept Wildcard Characters?

true

-include <string[]>

Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.

The Include parameter is effective only when the command includes the Recurse parameter or the path leads to the contents of a directory, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-exclude <string[]>

Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.

Required?

false

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-filter <string>

Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

Required?

false

Position?

2

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-name <SwitchParameter>

Retrieves only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-recurse <SwitchParameter>

Gets the items in the specified locations and in all child items of the locations.

Recurse works only when the path points to a container that has child items, such as C:\Windows or C:\Windows\*, and not when it points to items that do not have child items, such as C:\Windows\*.exe.

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-force <SwitchParameter>

Adds hidden files and directories to the output.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-codeSigningCert <SwitchParameter>

Retrieves only the certificates that have code signing authority. This parameter is valid only when using the Windows PowerShell Certificate Provider. For more information, see about_Provider and about_Signing.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-literalPath <string[]>

Specifies a path to one or more locations. Unlike Path, the value of LiteralPath is used exactly as typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks ('). Single quotation marks instruct Windows PowerShell not to interpret any characters as escape sequences.

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true <ByPropertyName>

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters.

Input and Return Types

The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet emits.

Input Type

String. You can pipe a path to Get-ChildItem.

Return Type

Objects. Returns objects representing the child items that it gets.

Notes

  • Get-Childitem does not get hidden items by default. To get hidden items, use -Force.
  • You can also refer to Get-ChildItem by its built-in aliases, "ls", "dir", and "gci". For more information, see about_Alias.

Example 1

C:\PS>get-childitem

This command gets the child items in the current location. If the location is a file system directory, it gets the files and sub-directories in the current directory. If the item does not have child items, this command returns to the command prompt without displaying anything.

The default display lists the mode (attributes), last write time, file size (length), and the name of the file. The valid values for mode are: d (directory), a (archive), r (read-only), h (hidden), and s (system).

Example 2

C:\PS>get-childitem . -include *.txt -recurse -force

This command retrieves all of the .txt files in the current directory and its subdirectories. The dot (".") represents the current directory and the Include parameter specifies the file name extension. The Recurse parameter directs Windows PowerShell to retrieve objects recursively, and indicates that the subject of the command is the specified directory and its contents. The force parameter adds hidden files to the display.

Example 3

C:\PS>get-childitem c:\windows\logs\* -include *.txt -exclude A*

This command lists the .txt files in the Logs subdirectory, except for those whose names start with the letter A. It uses the wildcard character (*) to indicate the contents of the Logs subdirectory, not the directory container. Because the command does not include the Recurse parameter, Get-Childitem does not include the content of directory automatically; you must specify it.

Example 4

C:\PS>get-childitem registry::hklm\software

This command retrieves all registry keys in the HKEY_LOCAL_MACHINE\SOFTWARE key in the registry of the local computer.

Example 5

C:\PS>get-childitem -name

This command retrieves only the names of items in the current directory.

Example 6

C:\PS>get-childitem cert:\. -recurse -codesigningcert

This command gets all of the certificates in the certificate store that have code-signing authority. The command uses the Get-Childitem cmdlet. The path specifies the Cert: drive exposed by the Windows PowerShell certificate provider. The backslash (\) symbol specifies a subdirectory of the certificate store and the dot (.) represents the current directory, which would be the root directory of the certificate store. The Recurse parameter specifies a recursive search and the CodeSigningCertificate parameter gets only certificates with code-signing authority.

Example 7

C:\PS>get-childitem * -include *.exe

This command retrieves all of the items in the current directory with a ".exe" file name extension. The wildcard character (*) represents the contents of the current directory (not the container). When using the Include parameter without the Recurse parameter, the path must point to contents, not a container.

See Also



Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker