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 - Asynchronous Processing

Reply
 
Old 06-04-2008   #1 (permalink)
Ozone


 
 

Asynchronous Processing

I wrote a script that will be used to upgrade the monitoring agents on
our servers, and the one challenge that I have not been able to
resolve is how to incorporate asynchronous processing into the
solution. Since this is a production script, I am using PS V1. The
script is written to take in a list of server, but the issue is that
the script will not begin upgrading ServerB unless ServerA is complete
AND no terminating errors were encountered while upgrading ServerA. I
have read the SDK regarding Runspaces, and i found the new-job.ps1,
PSThreading, and AsyncLib.ps1 scripts, but I have not been able to put
this together to create an asynchronous solution..

At this time, we are opening multiple PowerShell consoles, and running
the script against a single server, but I would like to automate this
process. We must be able to pass parameters and switches to the
script, and have multiple runspaces executing at the same time. So in
short, I would like to do something like this:

Pseudo Code:
Import-Csv "inputlist.csv" | foreach-object {
open a new runspace
execute the script with the correct parameters and switches
if ($?){Start another runspace and move to the next server}
if $numberofrunspace -eq 5 {loop until $numberofrunspace -le 4}
}

As soon as the runspace starts successfully, I would like to start
upgrading the next server in the input file. This is where I keep
running into the issue. If I can't get the second runspace to start
until the first loop is complete, I still do not have asynchronous
processing. Also, I would like to limit the number of runspaces to 5
so we don't have a runspace open for every server in the input file.

So in short, if anyone has figured out how to use runspaces and/or a
PS1 library to create an asynchronous processing solution, please let
me know...

Any help with this issue will be greatly appreciated.
Ozone

My System SpecsSystem Spec
Old 06-04-2008   #2 (permalink)
Shay Levi


 
 

Re: Asynchronous Processing



Running an external process asynchronously


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I wrote a script that will be used to upgrade the monitoring agents on
> our servers, and the one challenge that I have not been able to
> resolve is how to incorporate asynchronous processing into the
> solution. Since this is a production script, I am using PS V1. The
> script is written to take in a list of server, but the issue is that
> the script will not begin upgrading ServerB unless ServerA is complete
> AND no terminating errors were encountered while upgrading ServerA. I
> have read the SDK regarding Runspaces, and i found the new-job.ps1,
> PSThreading, and AsyncLib.ps1 scripts, but I have not been able to put
> this together to create an asynchronous solution..
>
> At this time, we are opening multiple PowerShell consoles, and running
> the script against a single server, but I would like to automate this
> process. We must be able to pass parameters and switches to the
> script, and have multiple runspaces executing at the same time. So in
> short, I would like to do something like this:
>
> Pseudo Code:
> Import-Csv "inputlist.csv" | foreach-object {
> open a new runspace
> execute the script with the correct parameters and switches
> if ($?){Start another runspace and move to the next server}
> if $numberofrunspace -eq 5 {loop until $numberofrunspace -le 4}
> }
> As soon as the runspace starts successfully, I would like to start
> upgrading the next server in the input file. This is where I keep
> running into the issue. If I can't get the second runspace to start
> until the first loop is complete, I still do not have asynchronous
> processing. Also, I would like to limit the number of runspaces to 5
> so we don't have a runspace open for every server in the input file.
>
> So in short, if anyone has figured out how to use runspaces and/or a
> PS1 library to create an asynchronous processing solution, please let
> me know...
>
> Any help with this issue will be greatly appreciated. Ozone
>

My System SpecsSystem Spec
Old 06-04-2008   #3 (permalink)
Shay Levi


 
 

Re: Asynchronous Processing


For a manual version:

1..5 | foreach {
$psi = new-object system.diagnostics.processStartInfo
$psi.fileName = "notepad.exe"
$psi.arguments= $profile
$psi.loadUserProfile = $false
$psi.useShellExecute = $false
$proc = [system.diagnostics.process]::start($psi)
write-host "Process #$_ launched"
}





---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> http://www.vistax64.com/powershell/1...al-process-asy
> nchronously.html#post726296
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> I wrote a script that will be used to upgrade the monitoring agents
>> on our servers, and the one challenge that I have not been able to
>> resolve is how to incorporate asynchronous processing into the
>> solution. Since this is a production script, I am using PS V1. The
>> script is written to take in a list of server, but the issue is that
>> the script will not begin upgrading ServerB unless ServerA is
>> complete AND no terminating errors were encountered while upgrading
>> ServerA. I have read the SDK regarding Runspaces, and i found the
>> new-job.ps1, PSThreading, and AsyncLib.ps1 scripts, but I have not
>> been able to put this together to create an asynchronous solution..
>>
>> At this time, we are opening multiple PowerShell consoles, and
>> running the script against a single server, but I would like to
>> automate this process. We must be able to pass parameters and
>> switches to the script, and have multiple runspaces executing at the
>> same time. So in short, I would like to do something like this:
>>
>> Pseudo Code:
>> Import-Csv "inputlist.csv" | foreach-object {
>> open a new runspace
>> execute the script with the correct parameters and switches
>> if ($?){Start another runspace and move to the next server}
>> if $numberofrunspace -eq 5 {loop until $numberofrunspace -le 4}
>> }
>> As soon as the runspace starts successfully, I would like to start
>> upgrading the next server in the input file. This is where I keep
>> running into the issue. If I can't get the second runspace to start
>> until the first loop is complete, I still do not have asynchronous
>> processing. Also, I would like to limit the number of runspaces to 5
>> so we don't have a runspace open for every server in the input file.
>> So in short, if anyone has figured out how to use runspaces and/or a
>> PS1 library to create an asynchronous processing solution, please let
>> me know...
>>
>> Any help with this issue will be greatly appreciated. Ozone
>>

My System SpecsSystem Spec
Old 06-04-2008   #4 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

Re: Asynchronous Processing

On Jun 4, 10:30*am, Ozone <rs_dov...@xxxxxx> wrote:
Quote:

> I wrote a script that will be used to upgrade the monitoring agents on
> our servers, and the one challenge that I have not been able to
> resolve is how to incorporate asynchronous processing into the
> solution. *Since this is a production script, I am using PS V1. *The
> script is written to take in a list of server, but the issue is that
> the script will not begin upgrading ServerB unless ServerA is complete
> AND no terminating errors were encountered while upgrading ServerA. *I
> have read the SDK regarding Runspaces, and i found the new-job.ps1,
> PSThreading, and AsyncLib.ps1 scripts, but I have not been able to put
> this together to create an asynchronous solution..
>
> At this time, we are opening multiple PowerShell consoles, and running
> the script against a single server, but I would like to automate this
> process. *We must be able to pass parameters and switches to the
> script, and have multiple runspaces executing at the same time. *So in
> short, I would like to do something like this:
>
> Pseudo Code:
> Import-Csv "inputlist.csv" | foreach-object {
> open a new runspace
> execute the script with the correct parameters and switches
> if ($?){Start another runspace and move to the next server}
> if $numberofrunspace -eq 5 {loop until $numberofrunspace -le 4}
>
> }
>
> As soon as the runspace starts successfully, I would like to start
> upgrading the next server in the input file. *This is where I keep
> running into the issue. *If I can't get the second runspace to start
> until the first loop is complete, I still do not have asynchronous
> processing. *Also, I would like to limit the number of runspaces to 5
> so we don't have a runspace open for every server in the input file.
>
> So in short, if anyone has figured out how to use runspaces *and/or a
> PS1 library to create an asynchronous processing solution, please let
> me know...
>
> Any help with this issue will be greatly appreciated.
> Ozone
Hi Ozone,

"Background jobs and PowerShell"
http://jtruher.spaces.live.com/blog/...628D!130.entry

(powershell 1.0)

- Oisin
My System SpecsSystem Spec
Old 06-05-2008   #5 (permalink)
Arnoud Jansveld


 
 

Re: Asynchronous Processing

Hi Ozone, you may want to take a look at my Split-Job script; it should do
what you need and even collects the output (if any) from each asynchronous
pipeline. In your case, you could run something like

Import-Csv "inputlist.csv" | Split-Job { Upgrade-Agent $_} -MaxPipelines 5 |
Out-File Upgrade-Agent.log

The blog post with the script is here:
http://www.jansveld.net/powershell/2...b-version-0-9/

Hope this helps,
Arnoud
--
http://www.jansveld.net/powershell


"Shay Levi" wrote:
Quote:

>
> For a manual version:
>
> 1..5 | foreach {
> $psi = new-object system.diagnostics.processStartInfo
> $psi.fileName = "notepad.exe"
> $psi.arguments= $profile
> $psi.loadUserProfile = $false
> $psi.useShellExecute = $false
> $proc = [system.diagnostics.process]::start($psi)
> write-host "Process #$_ launched"
> }
>
>
>
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > http://www.vistax64.com/powershell/1...al-process-asy
> > nchronously.html#post726296
> >
> > ---
> > Shay Levi
> > $cript Fanatic
> > http://scriptolog.blogspot.com
Quote:

> >> I wrote a script that will be used to upgrade the monitoring agents
> >> on our servers, and the one challenge that I have not been able to
> >> resolve is how to incorporate asynchronous processing into the
> >> solution. Since this is a production script, I am using PS V1. The
> >> script is written to take in a list of server, but the issue is that
> >> the script will not begin upgrading ServerB unless ServerA is
> >> complete AND no terminating errors were encountered while upgrading
> >> ServerA. I have read the SDK regarding Runspaces, and i found the
> >> new-job.ps1, PSThreading, and AsyncLib.ps1 scripts, but I have not
> >> been able to put this together to create an asynchronous solution..
> >>
> >> At this time, we are opening multiple PowerShell consoles, and
> >> running the script against a single server, but I would like to
> >> automate this process. We must be able to pass parameters and
> >> switches to the script, and have multiple runspaces executing at the
> >> same time. So in short, I would like to do something like this:
> >>
> >> Pseudo Code:
> >> Import-Csv "inputlist.csv" | foreach-object {
> >> open a new runspace
> >> execute the script with the correct parameters and switches
> >> if ($?){Start another runspace and move to the next server}
> >> if $numberofrunspace -eq 5 {loop until $numberofrunspace -le 4}
> >> }
> >> As soon as the runspace starts successfully, I would like to start
> >> upgrading the next server in the input file. This is where I keep
> >> running into the issue. If I can't get the second runspace to start
> >> until the first loop is complete, I still do not have asynchronous
> >> processing. Also, I would like to limit the number of runspaces to 5
> >> so we don't have a runspace open for every server in the input file.
> >> So in short, if anyone has figured out how to use runspaces and/or a
> >> PS1 library to create an asynchronous processing solution, please let
> >> me know...
> >>
> >> Any help with this issue will be greatly appreciated. Ozone
> >>
>
>
>
My System SpecsSystem Spec
Old 06-07-2008   #6 (permalink)
Karl Prosser[MVP]


 
 

Re: Asynchronous Processing

I've done very similar things arnoud, but i LOVE the design of this.. we
don't have to come back and check status of jobs being run async etc. it
just fits into the same workflow as your orginal script... I love it, at
first sight. I hope to get the chance to look at it in depth sometime.

Arnoud Jansveld wrote:
Quote:

> Hi Ozone, you may want to take a look at my Split-Job script; it should do
> what you need and even collects the output (if any) from each asynchronous
> pipeline. In your case, you could run something like
>
> Import-Csv "inputlist.csv" | Split-Job { Upgrade-Agent $_} -MaxPipelines 5 |
> Out-File Upgrade-Agent.log
>
> The blog post with the script is here:
> http://www.jansveld.net/powershell/2...b-version-0-9/
>
> Hope this helps,
> Arnoud
My System SpecsSystem Spec
Old 06-07-2008   #7 (permalink)
Karl Prosser[MVP]


 
 

Re: Asynchronous Processing

I've done very similar things arnoud, but i LOVE the design of this.. we
don't have to come back and check status of jobs being run async etc. it
just fits into the same workflow as your orginal script... I love it, at
first sight. I hope to get the chance to look at it in depth sometime.

Arnoud Jansveld wrote:
Quote:

> Hi Ozone, you may want to take a look at my Split-Job script; it should do
> what you need and even collects the output (if any) from each asynchronous
> pipeline. In your case, you could run something like
>
> Import-Csv "inputlist.csv" | Split-Job { Upgrade-Agent $_} -MaxPipelines 5 |
> Out-File Upgrade-Agent.log
>
> The blog post with the script is here:
> http://www.jansveld.net/powershell/2...b-version-0-9/
>
> Hope this helps,
> Arnoud
My System SpecsSystem Spec
Old 06-09-2008   #8 (permalink)
Ozone


 
 

Re: Asynchronous Processing

I want to thank everyone for the suggestions... They have given me
new ideas on how to finally incorporate asynchronous processing into
the script. Thanks for everyone's time, I really appreciate it...

Thanks
Ozone
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
asynchronous serial i/o .NET General
new process should be asynchronous .NET General


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