#PowerShellAsync base class for async-enabled PowerShell Cmdlets.
When you build PowerShell Cmdlets, it is required that calls to WriteObject, WriteVerbose, WriteWarning, etc be originated from BeginProcessing/ProcessRecord/EndProcessing method on the main thread!.
With a general move towards async code, it's become hard to use newer libraries inside the traditional PowerShell Cmdlets. Up until now :)
With 3 easy steps you can take advantage of the async programming:
- Install PowerShellAsync from nuget.org
PM> Install-Package PowerShellAsync
- Replace base class of your Cmdlet from PSCmdlet to AsyncCmdlet
[Cmdlet("Test", "SomethingCool")] public class TestSomethingCool : AsyncCmdlet
- Replace BeginProcessing/ProcessRecord/EndProcessing methods with their xxxAsync counterparts
protected override async Task ProcessRecordAsync()
- Enjoy!!!
To install PowerShellAsync, run the following command in the Package Manager Console
PM> Install-Package PowerShellAsync
please take a look at PowerShellAsyncExamples project, it contains an demo Cmdlet that can execute SQL statement on multiple servers takeing advantage of async API.