12

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

 3 years ago
source link: https://thomasrayner.ca/quick-tip-use-powershell-to-see-how-many-files-are-in-a-directory/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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?

PS> (Get-ChildItem -Path c:\temp\demo).count
3

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.

PS> (Get-AdUser -filter "Name -like 'Thomas *'").count
7

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

Written on August 16, 2017

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK