Is there a “Sum” function?


I’ve got following code snippet:

The last line obviously shows an error since there is no “Sum” function. Is there a convenient way to sum items in PowerShell?


You can use the Measure-Object cmdlet:

Note that it also works with properties of objects:

In the above example, we sum the lengths of the strings in the array by setting the -Property parameter to Length.


Is there a “Sum” function? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply