none
Powershell script: howto speed up with jobs? RRS feed

  • Question

  • Hi,

    I have a PS Script that checks a remote computer for: uptime, installed software, cpu & memory usage, antivirus status, local users, services if they are stopped or not etc.
    This takes quite some time.

    I'd like to launch some functions next to each other, f.e. get-uptime runs then it doesn't wait but fires next to it get-installedsoftware and next to that get-cpuandmemusage

    I guess I need to have jobs for that and would love to have a simple example of a job so I could integrate it in my script and speed it up (runs for 2 minutes now).

    Please advise.
    J.


    Jan Hoedt

    Monday, October 10, 2016 8:12 PM

Answers

  • Using PowerShell background jobs to run things in parallel does not always make sense. Each background job is a new PowerShell process that needs to be started startup and that process neesd to load all required modules again. This takes time and the time required might be more than the actual runtime you want to get rid of.

    I have successfully used https://github.com/nightroman/SplitPipeline but I am not sure if this pattern is applicable in your situation. There might be other modules that are not starting a new PowerShell process but thread within the current process.


    -Raimund


    Tuesday, October 11, 2016 7:28 AM

All replies

  • Commands do not run next to each other.  They run one after the other.  I have no idea what would make you thing otherwise.


    \_(ツ)_/

    Monday, October 10, 2016 8:49 PM
  • Hi Jan,

    PowerShell has a lot of internal help, that ships with all installations (may get broken on non-English installs though). So if you want to learn about jobs ... why not run:

    help about_jobs

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, October 11, 2016 6:56 AM
  • Using PowerShell background jobs to run things in parallel does not always make sense. Each background job is a new PowerShell process that needs to be started startup and that process neesd to load all required modules again. This takes time and the time required might be more than the actual runtime you want to get rid of.

    I have successfully used https://github.com/nightroman/SplitPipeline but I am not sure if this pattern is applicable in your situation. There might be other modules that are not starting a new PowerShell process but thread within the current process.


    -Raimund


    Tuesday, October 11, 2016 7:28 AM