I want to be able to invoke a command on a set of servers that the user specifies. This could be 1 server or it could be many. Here is what I was thinking of doing but it doesnt work. Does anyone have any thoughts?
That's because you're prompting by using Read-Host. That only takes a single value.
With that at the top of a script or function, PowerShell will handle the prompting, and it'll prompt for multiple values. You hit Enter on a blank to continue, and $ComputerName would be an array of computer names. That could be passed directly to the -ComputerName parameter of New-PSSession.
Now, alternately, I supposed you could
And $computers would contain the needed array of strings. But I prefer to let PowerShell do the heavy lifting – it's better at it.
You must be logged in to reply to this topic.