Q: What is an easy way to get a count of objects in Windows PowerShell?
Need a count of objects? PowerShell to the rescue.
John Savill
August 31, 2012
1 Min Read
A: If you have a large number of objects and need to get a count of them or generate statistics on them, you have a couple options.
The first is to pass the output to the PowerShell measure-object cmdlet. Here it is in action, showing what it returned:
PS C:> get-command | measure-object
Count : 994
Average :
Sum :
Maximum :
Minimum :
Property :
Another way would be to just get the count property of the command. You enter the following command and it returns just the count property, which you can see below:
PS C:> (get-command).count
994
Other options exist, such as using a custom variable incrementing, but the above two options are probably the easiest.
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like