PowerShell: How to List Unique File Types in Folder


You can use the following syntax in PowerShell to display a list of unique file types in each folder and subfolder of a directory:

Get-ChildItem -Recurse | Select-Object DirectoryName, Extension -Unique

This particular example will return all unique file types in each folder and subfolder of the current directory.

Here is what the various commands do:

  • Get-ChildItem – Recurse: Recursively retrieve all files from the current folder and all subfolders
  • Select-Object DirectoryName, Extension: Only return the directory path and extension of the files
  • -Unique: Only return unique extensions

The following example shows how to use this syntax in practice.

Example: How to List Unique File Types in Folders in PowerShell

Suppose that our current directory has the following path:

  • C:\users\bobbi\data1

We can use the following syntax to view all files in this directory, including files in subfolders:

Get-ChildItem -Recurse

The following screenshot shows how to use this syntax in practice:

We can see that the current directory contains the following files:

  • all_data.csv
  • coaches.txt
  • managers.txt
  • rosters.txt

This directory also has a subfolder named athletes that contains the following files:

  • coaches.txt
  • nba_data.xlsx
  • new_data.txt

We can use the following syntax to list only the unique file types in both the current directory and the subfolder:

Get-ChildItem -Recurse | Select-Object DirectoryName, Extension -Unique

The following screenshot shows how to use this syntax in practice:

PowerShell list unique file types

The output displays a list of unique file types in both the current directory and the subfolder.

From the output we can see that the current directory (data1) has the following types of files in it:

  • .csv
  • .txt

And we can see that the subfolder (athletes) has the following types of files in it:

  • .txt
  • .xlsx

Note: You can find the complete documentation for the Get-ChildItem cmdlet in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Delete All Files with Specific Extension
PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to Get File Extension

Leave a Reply