Automation

 View Only
  • 1.  general powershell question on start-job

    Posted Oct 13, 2020 10:33 AM

    I am trying to telnet 4125 Ips using Test-NetConnection. The below is the script. Here I used the script to execute in Parallel as a job. However After executing the job when I verified the child jobs only 5 jobs are running at single point of time and other jobs are in not started state.

    My question is can we increase the execution process of child jobs to more then 5?

    $ipslistcsv=Import-Csv -Path C:\Users\testuser\Desktop\VLANSORTEDLIST.csv -UseCulture

    $scriptasjob= $ipslistcsv | ForEach-Object -Parallel {

            if ((Test-NetConnection -ComputerName $_.IP -Port 3389 -WarningAction SilentlyContinue -ErrorAction SilentlyContinue).TcpTestSucceeded -eq $true) {

                "Connection establisted sucessfully over port 3389 for IP $($_.IP)"  

            }

            elseif ((Test-NetConnection -ComputerName $_.IP -Port 22 -WarningAction SilentlyContinue -ErrorAction SilentlyContinue).TcpTestSucceeded -eq $true) {

                "Connection establisted sucessfully over port 22 for IP $($_.IP)"   

            }

            else {

                "No Connection establised for IP $($_.IP)"

            }

        } -AsJob

    (Get-Job -Id $scriptasjob.id).ChildJobs



  • 2.  RE: general powershell question on start-job
    Best Answer

    Posted Oct 13, 2020 10:50 AM

    The ThrottleLimit parameter on the Foreach-Object cmdlet defaults to 5.



  • 3.  RE: general powershell question on start-job

    Posted Oct 13, 2020 12:51 PM

    Thanks LucD. Script execution speed improved after setting throttlelimit