View Single Post
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