I have a weird PowerShell problem. I am trying to pass into a class method multiple parameters, but it fails. I was able to pass in multiple parameters to a global function
You need to declare the parameters in the method definition:
[void]
myMethod( [array]$arguments ) {
for ($index = 0; $index -lt $arguments.Count; $index++) {
Write-Host $arguments[$index]
}
}
Note that I intentionally changed the automatic variable name args
to something else, otherwise it won't work.
In order to call the method, use the following syntax:
$myTestObj.myMethod(@('A', 'B', 'C'))
# or
$argument = 'A', 'B', 'C'
$myTestObj.myMethod($argument)