Get-ChildItem helps you see files and folders inside a folder. It is like looking inside a drawer to find what is there.
Get-ChildItem for listing in PowerShell
Get-ChildItem [-Path] <string> [-Filter <string>] [-Recurse] [-File] [-Directory]
-Path tells where to look. If you skip it, it looks in the current folder.
-Recurse means look inside all folders inside the folder, not just the top level.
Get-ChildItem
Get-ChildItem -Path C:\Users\YourName\Documents
Get-ChildItem -Path . -Filter *.txt
Get-ChildItem -Path C:\Projects -Recurse -File
This script first shows all files and folders in the current folder. Then it shows only folders. Finally, it lists all PowerShell script files (.ps1) inside the current folder and all folders inside it.
Write-Host "Files and folders in current directory:"; Get-ChildItem; Write-Host "\nOnly folders in current directory:"; Get-ChildItem -Directory; Write-Host "\nAll .ps1 files in current directory and subdirectories:"; Get-ChildItem -Filter "*.ps1" -Recurse -File;
Get-ChildItem runs fast for small folders but can be slower with many files or deep folders when using -Recurse.
Use -File to get only files, and -Directory to get only folders.
Common mistake: forgetting to use quotes around paths with spaces, like "C:\My Folder".
Get-ChildItem lists files and folders in a folder.
You can filter by file type or look inside subfolders with -Recurse.
Use -File or -Directory to list only files or only folders.