Get-ChildItem
Gets the items and child items in one or more specified locations.
Syntax
Items (Default)
Get-ChildItem
[[-Path] <string[]>]
[[-Filter] <string>]
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint32>]
[-Force]
[-Name]
[-UseTransaction]
[-Attributes <FlagsExpression[FileAttributes]>]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
LiteralItems
Get-ChildItem
[[-Filter] <string>]
-LiteralPath <string[]>
[-Include <string[]>]
[-Exclude <string[]>]
[-Recurse]
[-Depth <uint32>]
[-Force]
[-Name]
[-UseTransaction]
[-Attributes <FlagsExpression[FileAttributes]>]
[-Directory]
[-File]
[-Hidden]
[-ReadOnly]
[-System]
[<CommonParameters>]
Description
The Get-ChildItem
cmdlet gets the items in one or more specified locations. 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 and use the Depth parameter to limit the number
of levels to recurse.
Get-ChildItem
does not display empty directories. When a Get-ChildItem
command includes the
Depth or Recurse parameters, empty directories are not included in the output.
Locations are exposed to Get-ChildItem
by PowerShell providers. A location can be a file system
directory, registry hive, or a certificate store. For more information, see about_Providers.
Parameters
-Attributes
Gets files and folders with the specified attributes. This parameter supports all attributes and lets you specify complex combinations of attributes.
For example, to get non-system files (not directories) that are encrypted or compressed, type:
Get-ChildItem -Attributes !Directory+!System+Encrypted, !Directory+!System+Compressed
To find files and folders with commonly used attributes, use the Attributes parameter. Or, the parameters Directory, File, Hidden, ReadOnly, and System.
The Attributes parameter supports the following properties:
- Archive
- Compressed
- Device
- Directory
- Encrypted
- Hidden
- IntegrityStream
- Normal
- NoScrubData
- NotContentIndexed
- Offline
- ReadOnly
- ReparsePoint
- SparseFile
- System
- Temporary
For a description of these attributes, see the FileAttributes Enumeration.
To combine attributes, use the following operators:
!
(NOT)+
(AND),
(OR)
Do not use spaces between an operator and its attribute. Spaces are accepted after commas.
For common attributes, use the following abbreviations:
D
(Directory)H
(Hidden)R
(Read-only)S
(System)
Parameter properties
Type: | |
Default value: | None |
Accepted values: | Archive, Compressed, Device, Directory, Encrypted, Hidden, IntegrityStream, Normal, NoScrubData, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, Temporary |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Depth
This parameter was added in PowerShell 5.0 and enables you to control the depth of recursion. By
default, Get-ChildItem
displays the contents of the parent directory. The Depth parameter
determines the number of subdirectory levels that are included in the recursion and displays the
contents.
For example, Depth 2
includes the Path parameter's directory, first level of subdirectories,
and second level of subdirectories. By default directory names and file names are included in the
output.
Note
On a Windows computer from PowerShell or cmd.exe, you can display a graphical view of a directory structure with the tree.com command.
Parameter properties
Type: | UInt32 |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Directory
To get a list of directories, use the Directory parameter or the Attributes parameter with the Directory property. You can use the Recurse parameter with Directory.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | ad, d |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-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. Enter a path element or pattern, such
as *.txt
or A*
. Wildcard characters are accepted.
A trailing asterisk (*
) in the Path parameter is optional. For example, -Path C:\Test\Logs
or -Path C:\Test\Logs\*
. If a trailing asterisk (*
) is included, the command recurses into the
Path parameter's subdirectories. Without the asterisk (*
), the contents of the Path
parameter are displayed. More details are included in Example 5 and the Notes section.
Parameter properties
Type: | String[] |
Default value: | None |
Supports wildcards: | True |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-File
To get a list of files, use the File parameter. You can use the Recurse parameter with File.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | af |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Filter
Specifies a filter to qualify the Path parameter. The FileSystem
provider is the only installed PowerShell provider that supports the use of filters. Filters are
more efficient than other parameters, because the provider applies them when the cmdlet gets the
objects rather than having PowerShell filter the objects after they are retrieved. The filter string
is passed to the .NET API to enumerate files. That API only supports *
and ?
wildcards.
Parameter properties
Type: | String |
Default value: | None |
Supports wildcards: | True |
DontShow: | False |
Parameter sets
(All)
Position: | 1 |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Force
Allows the cmdlet to get items that cannot otherwise not be accessed by the user, such as hidden or system files. The Force parameter does not override security restrictions. Implementation varies among providers. For more information, see about_Providers.
Parameter properties
Type: | SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Hidden
To get only hidden items, use the Hidden parameter or the Attributes parameter with the
Hidden property. By default, Get-ChildItem
does not display hidden items. Use the Force
parameter to get hidden items.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | ah, h |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-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. Enter a path element or pattern, such as
"*.txt"
. Wildcard characters are permitted. The Include parameter is effective only when the
command includes the contents of an item, such as C:\Windows\*
, where the wildcard character
specifies the contents of the C:\Windows
directory.
Parameter properties
Type: | String[] |
Default value: | None |
Supports wildcards: | True |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-LiteralPath
Specifies a path to one or more locations. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
For more information, see about_Quoting_Rules.
Parameter properties
Type: | String[] |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | PSPath |
Parameter sets
LiteralItems
Position: | Named |
Mandatory: | True |
Value from pipeline: | False |
Value from pipeline by property name: | True |
Value from remaining arguments: | False |
-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. Wildcards are permitted.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | True |
DontShow: | False |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Path
Specifies a path to one or more locations. Wildcards are accepted. The default location is the
current directory (.
).
Parameter properties
Type: | String[] |
Default value: | Current directory |
Supports wildcards: | True |
DontShow: | False |
Parameter sets
Items
Position: | 0 |
Mandatory: | False |
Value from pipeline: | True |
Value from pipeline by property name: | True |
Value from remaining arguments: | False |
-ReadOnly
To get only read-only items, use the ReadOnly parameter or the Attributes parameter ReadOnly property.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | ar |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-Recurse
Gets the items in the specified locations and in all child items of the locations.
Parameter properties
Type: | SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Aliases: | s |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-System
Gets only system files and directories. To get only system files and folders, use the System parameter or Attributes parameter System property.
Parameter properties
Type: | SwitchParameter |
Default value: | None |
Supports wildcards: | False |
DontShow: | False |
Aliases: | as |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
-UseTransaction
Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.
Parameter properties
Type: | SwitchParameter |
Default value: | False |
Supports wildcards: | False |
DontShow: | False |
Aliases: | usetx |
Parameter sets
(All)
Position: | Named |
Mandatory: | False |
Value from pipeline: | False |
Value from pipeline by property name: | False |
Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
String
You can pipe a string that contains a path to Get-ChildItem
.
Outputs
Object
The type of object that Get-ChildItem
returns is determined by the objects in the provider drive path.
String
If you use the Name parameter, Get-ChildItem
returns the object names as strings.
Notes
- You can refer to
Get-ChildItem
by its built-in aliases,ls
,dir
, andgci
. For more information, see about_Aliases. Get-ChildItem
does not get hidden items by default. To get hidden items, use the Force parameter.- The
Get-ChildItem
cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, typeGet-PSProvider
. For more information, see about_Providers.