Powershell’s Invoke-Command won’t take in a variable for -ComputerName parameter?

Question:

I’m pulling my hair out here, because I just can’t seem to get this to work, and I can’t figure out how to google this issue. I’m running Powershell 2.0. Here’s my script:

The last command gives the error:

But when I copy the output of the Write-Output command to the shell and run that, it works just fine. How can I cast the string variable to something that Invoke-Command will accept? Thanks in advance!

Answer:

You declared your array incorrectly. Put a comma between strings and pipe it to for-each like:

Source:

Powershell’s Invoke-Command won’t take in a variable for -ComputerName parameter? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply