I running some test on Invoke Command and found some interesting result.
This is the success code snippet.
Invoke-Command -ComputerName serverA,serverB,serverC,serverD,serverE -ScriptBlock{Get-WindowsUpdate | Format-Table -AutoSize}
This is the code snippet which return error.
$servers="serverA,serverB,serverC,serverD,serverE"
Invoke-Command -ComputerName $servers -ScriptBlock{Get-WindowsUpdate | Format-Table -AutoSize}
Error Message:
Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
Why there is an error occur when read from variables? How to fix it?