Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - powershell script to execute simultaneously instead of sequentially

Reply
 
Old 07-17-2009   #1 (permalink)
jlo


xp 32
 
 

powershell script to execute simultaneously instead of sequentially

i would like to execute a script to execute the same command to a list of servers, listed in a text file (hopefully later from an excel file), simultaneously by opening separate foreground powershell windows to run the command per machine name.

i have figured out how to run it sequentially by pulling the array of names from the txt file and using the names as the variable but with many machines - this takes much too long. i dont want to do this as a background job as i like seeing the action as it happens on all the machines.
i can and do currently have a script that i can enter the names individually as well but this is error prone as i can skip a name by accident.

i.e. as an example - i would like to take a text file with 50 pc names - and have a script open 50 seperate powershell windows simlultaneously per pc name and ping them all and import the results back to the local machine....
this should be rather simple but i cant figure it out...!

My System SpecsSystem Spec
Old 07-18-2009   #2 (permalink)
Joel Bennett


 
 

Re: powershell script to execute simultaneously instead of sequentially

Well, opening 50 console windows is not going to be trivial, in terms of
time/resources, but ... you would run something like:

# get your data here, somehow
$servers = gc servers.txt

$procs = $(
foreach($server in $servers) {
$si = New-Object -TypeName System.Diagnostics.ProcessStartInfo
$si.FileName = "powershell.exe"
$si.Arguments = "-command ping.exe $server"
[diagnostics.process]::Start($si)
}
)

But there's no easy way to get the output from a console window if you
let it start up in GUI mode like that, so I definitely don't recommend
going that route.
--
Joel


jlo wrote:
Quote:

> i would like to execute a script to execute the same command to a list
> of servers, listed in a text file (hopefully later from an excel file),
> simultaneously by opening separate foreground powershell windows to run
> the command per machine name.
>
> i have figured out how to run it sequentially by pulling the array of
> names from the txt file and using the names as the variable but with
> many machines - this takes much too long. i dont want to do this as a
> background job as i like seeing the action as it happens on all the
> machines.
> i can and do currently have a script that i can enter the names
> individually as well but this is error prone as i can skip a name by
> accident.
>
> i.e. as an example - i would like to take a text file with 50 pc names
> - and have a script open 50 seperate powershell windows simlultaneously
> per pc name and ping them all and import the results back to the local
> machine....
> this should be rather simple but i cant figure it out...!
>
>
My System SpecsSystem Spec
Old 08-21-2009   #3 (permalink)
jlo


xp 32
 
 

i was able to apply this for the ping but this didnt work when i tried to use an existing script in place of the ping command. its a great start though... any thoughts on how to adapt it to a script as the command and the location variable pulled from the txt file?
My System SpecsSystem Spec
Old 08-27-2009   #4 (permalink)


XP
 
 

Re: powershell script to execute simultaneously instead of sequentially

An another way :
Split-Job (use runspace Posh V1)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Permissions to execute the script VB Script
execute Exchange script from DOS - how to get result? PowerShell
Execute a powershell script from a webpage PowerShell
Powershell Execute process PowerShell
execute powershell script from commmand line PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46