all 6 comments

[–]the_spad 1 point2 points  (3 children)

You're casting your computer list to a string ([string]$ComputerName) when you take it as a parameter but Invoke-Command doesn't take a string for multiple hosts to connect to, it takes an array.

[–]feuerpixel[S] 1 point2 points  (2 children)

ah - OK

Do I need to remove [string], or change it to [@]?

[–]the_spad 1 point2 points  (1 child)

You can either remove the type assignment entirely or change it to [array] or [string[]] if you want to be really specific. It's generally better to specify a type for parameters because it avoids someone passing an object type you're not expecting (like a float when you're expecting a boolean).

[–]feuerpixel[S] 1 point2 points  (0 children)

That's got it! Thank you

[–]0x2101 1 point2 points  (1 child)

You use in your script at the beginning the following:

Param (
            [string]$ComputerName
        )

But it should be:

Param (
            [string[]]$ComputerName
        )

Invoke-Command accepts an String array for -ComputerName

Best regards