A wrapper presents lower-level components through a consistent, simpler interface. PowerShell cmdlets translate commands into .NET Framework, CIM, COM, and Windows API operations, hiding implementation details and reducing maintenance. section 25.1
A useful PowerShell wrapper:
- Follows native command patterns, including parameters and pipeline input. section 25.3
- Keeps setup in Begin, processes input in Process, and exposes useful implementation choices such as synchronous or asynchronous behavior. section 25.3
- Creates a reusable seam for help, team reuse, and Pester mocking when direct .NET calls cannot be mocked. section 25.3
Wrapping a speech synthesizer
Invoke-Speech loads System.Speech once, accepts text from the pipeline, and calls Speak for each phrase. An Asynchronous switch selects SpeakAsync; assigning its return value to $null suppresses unwanted completion objects. section 25.3
Listing 25.1 Wrapper for the speech synthesizer
function Invoke-Speech {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)] #1
[string[]]$Text
)
BEGIN {
Add-Type -AssemblyName System.Speech #2
$speech = New-Object -TypeName
System.Speech.Synthesis.SpeechSynthesizer
}
PROCESS {
foreach ($phrase in $text) {
$speech.speak($phrase)
}
}
END {}
}
"One","Two","Three" | Invoke-Speech
Inspect the complete Invoke-Speech wrapper, including CmdletBinding, pipeline parameters, assembly setup, and Begin/Process structure. section 25.3



