Thursday, October 9, 2025
HomePowershellMeasure Objects (Rely, Common, Sum …) – SID-500.COM

Measure Objects (Rely, Common, Sum …) – SID-500.COM


PowerShell

The Measure-Object cmdlet counts objects. However it may well do much more. We will calculate the sum, the typical and far more. On this weblog submit I present a couple of examples with Measure-Object. Let’s dive in.

First of To start with, we are able to name up the assistance for Measure-Object right here:

https://study.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/measure-object?view=powershell-7.4

Now I’ve ready a couple of examples. I like to recommend copying these examples into ISE or VS Code and executing them there to study the mechanics and the probabilities of this cmdlet.

Right here we go:

# Measure-Object

$numbers = 1,2,3,4,5,6,7,8,9,10
$numbers | Measure-Object -Common -Most -Minimal -Sum

$array = "apple", "banana", "cherry"
$array | Measure-Object

$array = "apple", "banana", "cherry"
$array | Measure-Object -Most -Property Size

$textual content = "Good day, world!"
$textual content | Measure-Object -Line -Phrase -Character

"One", "Two", "Three", "4" | Set-Content material -Path $hometmp.txt
Get-Content material $hometmp.txt | Measure-Object -Character -Line -Phrase


# Measure-Object in Actual-World Situations

# Rely Instructions
Get-Command | Measure-Object | Choose-Object -Property Rely
# Cound ADUsers
Get-ADUser -Filter 'LogonCount -eq "0"' -Properties LogonCount | Measure-Object 
# Rely Sum of Recordsdata in a Folder and Subfolders
(Get-ChildItem -Path "C:UsersPatrickGruenauersid-SynologyDriveVideosUdemy" -Recurse -Embody *.mp4 | 
Measure-Object Size -Sum).Sum /1GB

I hope you had been capable of study a couple of issues from this weblog submit that you may put into observe. See you subsequent time!

Printed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2025], IT-Coach, IT-Advisor, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments