Home » How to List Files in Directory Using PowerShell

How to List Files in Directory Using PowerShell

To list files in a directory using PowerShell, you can use the Get-ChildItem cmdlet. The Get-ChildItem command retrieves the items from the specified directory.

You can use the following method to list files in a directory using PowerShell.

Method 1: List all files in a directory using PowerShell

Get-ChildItem -Path $directoryPath -Recurse

This example returns the list of all files in a specified directory $directoryPath.

The following examples show how to use this method.

How to List All Files in a Directory Using PowerShell

To list all files in a folder and subfolders using PowerShell, use the Get-ChildItem cmdlet along with the -Recurse parameter.

The following example shows how to do it with syntax.

# Specify the directory path
$directoryPath = "C:\temp\log\"

# List all files in a directory
Get-ChildItem -Path $directoryPath -Recurse

Output:

PowerShell list all files in a directory
PowerShell lists all files in a directory

This example recursively retrieves all the files from the specified directory and subdirectories.

Conclusion

I hope the above article on listing all files in a directory using the PowerShell Get-ChildItem cmdlet is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.