The module provides an abstract AsyncPSCmdlet base class for writing PowerShell cmdlets that use asynchronous Task-based lifecycle methods. It also provides a new improved, backward compatible API for writing binary cmdlets.
AsyncPSCmdlet : PSCmdlet
Implement these Async methods
Begin()— replacesBeginProcessing()Process()— replacesProcessRecord()End()— replacesEndProcessing()
The base class exposes internal helpers for writing to the PowerShell pipeline in a safe async-friendly way:
AddOutput(object item, bool raw = false)— buffers an item for later emission to the pipeline.Debug(string message, bool raw = false)Verbose(string message, bool raw = false)Warning(string message, bool raw = false)Info(string message, string[]? tags = null, bool raw = false)Console(string message, bool raw = false)Error(...)— overloads for exception-based and message-based errors.
Error(...) supports:
Exception exceptionstring message- optional
recommendedAction - optional
errorId - optional
targetObject - optional
errorDetailsMessage - optional
category terminatingto throw a terminating error whentrue
public sealed class ExampleCmdlet : AsyncPSCmdlet
{
protected override async Task Process()
{
await Task.Delay(100);
AddOutput("done");
}
}- Use the helper methods above instead of calling
WriteObject/WriteErrordirectly from async work. - The async pipeline buffers output and emits it back to PowerShell in the cmdlet execution thread.