Improve PowerShell Code Efficiency with .NET RunSpaces
summary
Demo shows using .NET runspaces to parallelize PowerShell work by instantiating runspace pool from System.Management.Automation, adding scripts with BeginInvoke/Invoke, and disposing pools afterward. A custom module (expand extender text report) and an invoke-extender-start-index runspace process large text reports and cuts an hours-long import to about 15 minutes in one case and a test of ~11,000 reports from ~63s to ~33s. Examples use Create, AddScript/AddCommand, and RunspaceFactory methods and measure real timing.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:55Synchronous processing importance
- 3:21Asynchronous processing methods
- 6:55PowerShell and .NET basics
- 9:02.NET namespaces overview
- 12:36Classes and methods in .NET
- 15:07Assemblies in PowerShell
- 21:56Creating .NET RunSpaces
- 24:30RunSpace execution
- 26:42RunSpace pools explained
- 31:52Practical RunSpace demo
- 34:17Real-world performance fix
- 37:40Live performance demo
- 41:37Best practices
- 42:43Further learning resources
related talks
01h 33mThe Guts of the PowerShell VSCode Extension
44m99 Problems, but Slow PowerShell Ain't One!
01h 45mWriting Award Winning PowerShell Functions and Script Modules
01h 16mLevel Up Your PowerShell: Essential Tips, Tricks, and Techniques
51mDon't do that, do this instead: PowerShell worst practices and..
01h 37mMore Game Breaking PowerShell
48mUnexplained phenomena: powerful tricks you likely didn't know were even possible
01h 00mThe Enterprise Scripting Workshop
