Last Updated on February 25, 2024 by Mathew Diekhake

I want to use the Powershell get-childitem filter to get files only, folders only, to exclude, to get a full path, and other filters. Resolution:

The following tutorial demonstrates how to use the Powershell get-childitem command to get items in one or more specified locations when using a version of the Windows operating system.

You can use the get-childitem command in Windows PowerShell to get the items and items inside a container (child items) in one or more specified locations.

The Get-ChildItem cmdlet does not display empty items due to the Depth or Recurse parameters removing them from the output.

How to Use get-childitem in PowerShell

You can use the get-childitem filter from the Windows Terminal app. Here is how to do that:

1. Open the Windows Terminal app. See this tutorial for how to open Windows Terminal: How to Open Elevated Windows Terminal as Administrator in Windows 11 [Tutorial]

2. From the Windows PowerShell shell, type your code using the following guidelines:

Get-ChildItem -Path C:\PowerShell\

Notes:

  • In the example above, the get-childitem command gets the child items from the C:\PowerShell\ path because you have used the -Path parameter.
  • Your Windows PowerShell will have set up some data store locations for you. These locations are skin to a file system drive, only for PowerShell. These PowerShell drives could be set up on the current file system drivers, such as the C and D drives. However, it’s also possible to create your own PowerShell drives. Once you create these PowerShell drives, they can only be accessed from PowerShell itself; you cannot open them via File Explorer or Cmd.exe.

3. PowerShell get-childitem Files Only

a. You can use the get-childitem command to get files only:

PS C:\> Get-ChildItem -Path D:\PowerShell\ -File

4. PowerShell get-childitem File Name Only

a. You can use the get-childitem command to get the file name:

PS C:\> Get-ChildItem -Path D:\PowerShell -File | Select Name

5. PowerShell get-childitem File Size Only

a. You can use the get-childitem command to get the file size only:

Get-ChildItem -Path D:\PowerShell -File | Select Length

6. PowerShell get-childitem for Specific User

a. You can use the get-childitem command to get files owned by specified users:

Get-childitem -Path D:\LogTest\FTP-02\ -recurse | get-acl | where {$_.Owner -match "ShellAdmin"}

7. PowerShell get-childitem Hidden Files and Directory Only

a. You can use the get-childitem command to get the hidden files and directories:

Get-ChildItem -Path D:\LogTest\FTP-01\ -Attributes !Directory,!Directory+Hidden

8. PowerShell get-childitem Excluded Folders Only

a. You can use the get-childitem command to get excluded folders:

Get-ChildItem -Path D:\PowerShell\* -Directory -Name -Exclude FTP-101,FTP-102

9. PowerShell get-childitem Include Multiple Extensions

a. You can use the get-childitem command to include multiple extensions:

Get-ChildItem -Path D:\PowerShell\* -Include *.zip,*.txt

10. PowerShell get-childitem for Registry Keys

a. You can use the get-childitem command to get the registry keys:

Get-ChildItem -Path HKLM:\Software

11. PowerShell get-childitem for Certificates

a. You can use the get-childitem command to get all certificates:

Get-ChildItem -Path Cert:\* -Recurse

12. PowerShell get-childitem to Get Recurse

a. You can use the get-childitem command to get the Recurse:

Get-ChildItem -Path D:\PowerShell\ -Recurse -Force -File

In conclusion, that is how to use the get-childitem command in PowerShell.

Related Tutorials