Hanging by a Thread
Over the last few weeks, we've been exploring techniques and concepts that you can use to scale your PowerShell scripting. Time is valuable, and there is never enough of it, so anything we can do to get more done in less time is worth learning. I've demonstrated various solutions because the correct answer will depend on the command or PowerShell expression and where it will be executed.
The appropriate solution may also depend on how you intend to consume the results. Do you need to pipe the results to another command immediately? Do you need to save the output for re-use? What version of PowerShell are you using?
As I promised at the end of the last article, there is one more potential solution I want to explore, and that is the use of a thread job. A thread job is similar to a background job. Background jobs run in a separate and new PowerShell runspace, which requires processing overhead. A thread job runs in individual threads spawned by the local process, i.e., PowerShell. This technique makes it easier for the thread job to inherit the parent environment and requires less overhead.
To create a thread job, you must install the ThreadJobs module from the PowerShell Gallery.