Is there a “Sum” function?

Question:

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?

Answer:

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.

Source:

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

Leave a Reply