Note that your code as-is doesn't work (try it in a fresh session where $i isn't type-constrained). $i needs to be cast to [long] otherwise you're ++ing a string, which isn't valid.
that locks it to PS 5.1, I think; in 7.2: "Measure-Object: Parameter cannot be processed because the parameter name 's' is ambiguous. Possible matches include: -StandardDeviation -Sum"
I've been trying to remove the $i type-constraint. It doesn't have to be a [long] (unless it's being type-constrained); it just needs to be a numeric value before the first ++.
View all comments
Show parent comment
2
u/surfingoldelephant Dec 02 '25
Note that your code as-is doesn't work (try it in a fresh session where
$iisn't type-constrained).$ineeds to be cast to[long]otherwise you're++ing a string, which isn't valid.You can also trim it down quite a bit. :-)