Blog Post

Scaling PowerShell – Lessons from a Technical Interview

,

Recently, I was in a technical interview where the topic of running PowerShell at scale came up. Although I’ve worked with PowerShell for quite some time, I realized I’d grown comfortable with “my” environment. Script runtimes and long-running processes were not a significant concern.

 

I’d encountered PowerShell jobs and parallel execution before, but never felt the need to dive deep. That changed after the interview. It sparked some curiosity and led me to explore how PowerShell handles parallelism. Turns out, it’s a great topic for a blog.

There are several ways to execute tasks concurrently in PowerShell, and the approach depends on which version you are using.

PowerShell 6 and earlier:

You’ll typically use the

Start-Job command. Below is an example of using the jobs method.

  1. Initialize a job tracking variable
  2. Define your remote connections
  3. Start jobs in a loop

PowerShell 7 and newer:

You gain access to the

ForEach-Object -Parallel feature, which simplifies parallel execution.

In the first execution, I used the

-Parallel parameter, which returned the list of servers based on the order in which each completed. This reflects the true parallelism. In contrast, the second run omitted the

-Parallel, and the results were returned sequentially, matching the order in which the servers were processed.


To explore this functionality in depth, review the resources below.

Microsoft Learning

PowerShell Commands

StackOverflow

 

The post Scaling PowerShell – Lessons from a Technical Interview appeared first on GarryBargsley.com.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating