Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell Runspace

$
0
0
I have a question on the runspace, I am also trying to implement this, but using a foreach loop and with a runspace, can this be done? I have a foreach loop for each database, then i am doing step 3 in the foreach loop (3. Create runspace and start it) like so: 

ForEach ($DB in $Databases)
{
    # 3 Create runspace and start it
    $runspace = [PowerShell]::Create()
    [void]$runspace.AddScript($scriptblock)
    [void]$runspace.AddArgument($DB.name)
    [void]$runspace.AddArgument($BackupType.ToString())
    [void]$runspace.AddArgument($BackupPath.ToString())
    $runspace.RunspacePool = $pool
$runspaces += [PSCustomObject]@{ Pipe = $runspace; Status = $runspace.BeginInvoke() }

}

this does work, However the problem or error I am getting is 
Exception calling "EndInvoke" with "1" argument(s): "The WriteObject and 
WriteError methods cannot be called from outside the overrides of the 
BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only 
be called from within the same thread. Validate that the cmdlet makes these 
calls correctly, or contact Microsoft Customer Support Services.

which when i see the backup is happening for each database, it seems to overwrite one over the other, and not backing all of them up parallel... do you by chance know what i may be doing wrong?

thanks in advance

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>