One-To-Many Powershell Scripts
Posted
by
Matt
on Server Fault
See other posts from Server Fault
or by Matt
Published on 2011-10-10T23:13:57Z
Indexed on
2012/10/03
9:40 UTC
Read the original article
Hit count: 310
powershell
|WinRM
I'm trying to create a script to run as a scheduled task, which will run against multiple servers and retrieve some information.
To start with, I populate the list of servers by querying AD for all servers that match a certain set of criteria, using Get-ADComputer.
The problem is, the list is returned as an object, which I can't then pass to the New-PSSession list. I have tried converting it to a comma-seperated string by doing the following:
foreach ($server in $serverlist) {$newlist += $server.Name + ","}
but this still doesn't work.
the alternative is to iterate through the list and run the various commands against each server one at a time, but my preference would be to avoid this and run them using one-to-many remoting.
UPDATE: To clarify what I want to end up being able to do is using -ComputerName $serverlist
, so I want $serverlist to be a string rather than an object.
UPDATE 2: Thanks for all the suggestions. Between them and my original method I'm starting to wonder whether -ComputerName
can accept a string variable? I've got varying degrees of success getting the list of computers converted to a comma separated string, but no matter how I do it I always get invalid network address.
© Server Fault or respective owner