Quick Tip: Use PowerShell To See How Many Files Are In A Directory

Here’s a way to see how many files are in a directory, using PowerShell.

As you likely know, you can use Get-ChildItem to get all the items in a directory. Did you know, however, that you can have PowerShell quickly count how many files there are?

I probably could have counted the files in this specific directory pretty easily myself, since there’s only 3 of them. If you want to see how many files are in an entire folder structure, use theĀ -Recurse flag to go deeper.

You can do this with any output from a cmdlet when it’s returned in an array of objects. Check this out.

In my test Active Directory, there are 7 AD users with a name that matches the pattern “Thomas *”.

0 thoughts on “Quick Tip: Use PowerShell To See How Many Files Are In A Directory

  1. This does return both files and folders though, so in that sense it does not return the count of files in a folder, rather the number of files and folders.

    1. Correct, do keep in mind this only works for PowerShell 3.0 and onward as those parameters were introduced in that version.

Leave a Reply

Your email address will not be published. Required fields are marked *