0

The following function works:

function myFunc1($arr1)
{
    $arr1 | Measure-Object -Maximum
}  
myFunc1(@(1,2,3))

But when I add a second parameter, it does not:

function myFunc2($arr1, $arr2)
{
    $arr1 | Measure-Object -Maximum
}
myFunc2(@(1,2,3), @(1,2,3))

It gives me this error:

Measure-Object : Cannot compare "System.Object[]" because it is not IComparable.
At C:\Users\bob\Documents\test2.ps1:3 char:13
+     $arr1 | Measure-Object -Maximum
+             ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Measure-Object], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.MeasureObjectCommand

All I did was add a send parameter, $arr2, and it broke the earlier code. I do not understand why the addition of $arr2 would affect calling Measure-Object on $arr1.

PortMan
  • 4,205
  • 9
  • 35
  • 61
  • 2
    Don't call PowerShell functions with parentheses: `myFunc2(@(1,2,3), @(1,2,3))`. Supply the parameters as if it were a cmdlet or a traditional command-line tool: `myFunc2 -arr1 @(1,2,3) -arr2 @(1,2,3)`. You can usually leave out the parameter names: `myFunc2 @(1,2,3) @(1,2,3)` – boxdog Oct 23 '19 at 12:44
  • That's it! I've been spending too much time on python lately. :) – PortMan Oct 23 '19 at 12:51

0 Answers0