Ajay Dwivedi has a script for us:
As a database administrator, often I have to fetch some metadata from all the SQLServers that we have. Other times, I have to execute some DDL or DML on all the servers.
In this blog and shared video, I show how to write a multiple server PowerShell script where server list source could range from raw text files to some inventory-based query result.
This is a serial operation, so you’re hitting one instance at a time. I’ve noticed that Powershell has about a half-dozen ways of performing parallel actions but they all seem to come with at least one fatal flaw.
I would be interested in the fatal flaws you mention!
I have ps scripts that loop through servers serially, and always wanted to convert them to parallel some day. If serial is better/more stable or whatever it is, I would really be interested to know the details 🙂
It’s been a few years since I needed to do this, but scraping through the memories and doing a few quick searches:
– Foreach-Object -Parallel (https://devblogs.microsoft.com/powershell/powershell-foreach-object-parallel-feature/) adds a fair amount of overhead for procesing.
– PSJobs (https://adamtheautomator.com/powershell-multithreading/) is unnecessarily complicated when all I want to do is “execute each item in this list in parallel.” I don’t think I tried runspaces (ibid).
– Thread jobs (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_thread_jobs?view=powershell-7.4) were okay, though I vaguely recall some limitations in executing custom code that left me frustrated.
– Workflows (https://learn.microsoft.com/en-us/powershell/module/psworkflow/about/about_workflows?view=powershell-5.1) are right out, as they aren’t even available anymore.
So yeah, “fatal flaw” was an overstatement for dramatic purposes, but there didn’t seem to be one technique that worked well and was easy to use. Foreach-Object -Parallel is probably the best approach nowadays, though I yearn for something as simple as PSeq in F# (https://fsprojects.github.io/FSharp.Collections.ParallelSeq/), which operates almost exactly the same as a normal Sequence but gives you parallelism.
Ok cool thank yo for the detailed reply!
I’ve read about the psjobs and thread jobs but they seemed…. weird 😀
Haven’t read about foreach object parallel so I’ll take a look at that. I’m not usually doing anything too complicated to the servers so that might work for me.
Thank you!