Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Limited powershell start-jobs

$
0
0

I curious if you can answer this or point me in the right direction.  ( I asked this on Stackoverflow and no one seems to be able to provide any input. )

 

I've written a script that tests/monitors urls.  I'm not posting the code ( unless you want me to ) because there is no error in the code.  It works great.  I can even scriptblock run it as part of start job.  The issue I have seems to be that I can not run more than 3 jobs at time.. or they hang.  I'm not sure why this is.  I can run it for a total of 15 urls throttled to 3 and it's great.  If I try to run it on 15 urls with 4 as my run limit, they will hang.. and I can kill one at a time.. until only 3 remain and those will finish.  So it seems that I can only start a total of 3 powershell instances or they hang.  Anyone explain why this is?  All my searches lead me to pages that show how to throttle and it's not really my issue.

The code is currently limited by input not by code, file has x number of urls in it.

 

_________________________

Watching the processes, each consumes about 25MBs of memory and sits there idle... If I kill one the other 3 will start using cpu and process go up to maybe 30MBs of memory and terminate completed.  System has 8GBs of memory & a quad cord I5-2400 CPU @ 3.10GHz.  As requested... I've tried in on my machine, stats above, and on 2008 R2 servers thinking it may be a system issue.  Allowed stacks in Winrm is currently set at 30

 

    Param(

    $file

    )

    $testscript =

    {

    Param(

    [string]$url,

    #[ValidateSet('InternetExplorer','Chrome','Firefox','Safari','Opera', IgnoreCase = $true)]

    [string]$browser="InternetExplorer",

    [string]$teststring="Solution Center",

    [int]$timeout=20,

    [int]$retry

    )

    $i=0

    do {

    $userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::$browser

    $data = Invoke-WebRequest $url -UserAgent $userAgent -TimeoutSec $timeout

    $data.Content

    $findit = $data.Content.Contains($teststring)

    $i++

    If ($findit){

    break

    }

    }

    while ($i -lt $retry)

 

    if(!$findit) {

    Echo "opcmsg a=PSURLCheck o=NHTSA msg_t='$teststring was not found on $url or $url failed to load'"

 

    }

    }

    $urls = Import-Csv $file | % {

 

    Start-Job -ScriptBlock $testscript -ArgumentList $_.url, $_.browser, $_.teststring, $_.retry

 

    }

    While (@(Get-Job | Where { $_.State -eq "Running" }).Count -ne 0)

    {  Write-Host "Processing URLs..."

       Get-Job

       Start-Sleep -Seconds 5

    }

    $Data = ForEach ($Job in (Get-Job)) {

       Receive-Job $Job

       Remove-Job $Job

    }

    $data | select *

 

_____________________________________________________

So I've used new system.net.webclient and I've even tried doing this with [System.Collections.Queue]... but all three methods use Jobs... so it appears.. I can not run more than three start jobs at any one time.


Viewing all articles
Browse latest Browse all 6937

Trending Articles