PowerShell Genie

Get-ChildItem

Use Get-ChildItem to get the items and child items in one or more specified locations.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Get-ChildItem

Syntax

1PS> Get-ChildItem [[-Path] <string[]>] [[-Filter] <string>] [-Include <String[]>] [-Exclude <String[]>] [-Recurse] [-Depth <UInt32>] [-Force] [-Name] [<CommonParameters>]
See the command anatomy

Inspect this authored example with fictional data in the bounded browser model. The numbered stages show how its objects change.

Get-ChildItem [[-Path] <string[]>] [[-Filter] <string>] [-Include <String[]>] [-Exclude <String[]>] [-Recurse] [-Depth <UInt32>] [-Force] [-Name] [<CommonParameters>]
  1. Stage 1Get-ChildItem-Path -Filter -Include -Exclude -Recurse -Depth -Force -Name

    Try it

    Windows PowerShell

    Browser simulation · fictional data; no changes to your computer.

    Interactive simulation · fictional data

    Examples

    Get-ChildItem -File

    1PS> Get-ChildItem C:\Logs -File
    Show reference output

    Illustrative output · values vary by environment

    Name        Length    Extension
    ----------  --------  ---------
    app.log     12582912  .log     
    readme.txt  2048      .txt     
    errors.log  26214400  .log     
    trace.log   524288    .log     

    Get-ChildItem -Filter *.log

    1PS> Get-ChildItem C:\Logs -File -Recurse -Filter *.log
    Show reference output

    Illustrative output · values vary by environment

    Mode   LastWriteTime      Length  Name
    -----  -----------------  ------  ----------
    -a---  9/10/2026 8:41 PM  4096    app.log

    List all with Get-ChildItem

    1PS> Get-ChildItem Cert:\LocalMachine\My
    Show reference output

    Illustrative output · values vary by environment

    Name        Length    Extension
    ----------  --------  ---------
    app.log     12582912  .log     
    readme.txt  2048      .txt     
    errors.log  26214400  .log     
    trace.log   524288    .log     

    Parameters

    Parameter definitions:

    • -Path
    • -Filter
    • -Include
    • -Exclude
    • -Recurse
    • -Depth
    • -Force
    • -Name

    Get-ChildItem on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Get-ChildItem when you need to get the items and child items in one or more specified locations. Review syntax and sample output, then try an example in the browser lab. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: Access denied during recursion can leave an incomplete inventory. Record inaccessible paths, use an appropriate account and do not label the result complete when some directories could not be read. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Get-Item. Get-ChildItem enumerates children of a container; Get-Item returns the item at the path itself. Use the appropriate scope when a report must list files rather than describe its root directory. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Get-ChildItem reference on Microsoft Learn

    Put this command to work

    Find large log files

    Return Name and Length for .log files larger than 10,000,000 bytes.

    Review the lesson

    Recap

    Get-ChildItem Use Get-ChildItem to get the items and child items in one or more specified locations.

    Next: Get-Content
    Genie guideGet-ChildItem

    Use Get-ChildItem to get the items and child items in one or more specified locations. The console below is pre-loaded — run it, then change a value and run it again.