0

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?

1 Answer 1

2

Parameter Computers accepts collection of strings. The comma is regarded as a separator, to build a collection. Using it as: $servers="serverA,serverB,serverC,serverD,serverE" is one large string, containing commas, not a collection of strings.

It should be: $servers="serverA","serverB","serverC","serverD","serverE"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.