process { foreach ($elementin$Object) { "Processing received element $element..." } } }
请注意如何通过参数调用函数:
1 2 3 4 5 6 7 8
PS C:\> Process-Data -Object 1 Processing received element 1...
PS C:\> Process-Data -Object 1,2,3,4 Processing received element 1... Processing received element 2... Processing received element 3... Processing received element 4...
您也可以通过管道传送信息:
1 2 3 4 5
PS C:\> 1..4 | Process-Data Processing received element 1... Processing received element 2... Processing received element 3... Processing received element 4...
Add-Type-AssemblyName System.Speech $speaker = [System.Speech.Synthesis.SpeechSynthesizer] $preInit $null = $Speaker.SpeakAsync(“Oh boy, that was a New Year’s party. I guess I need a little break.”)
functionTest-Stream { #region These are all the same and define return values 'Return Value 1' echo'Return Value 2' 'Return Value 3' | Write-Output #endregion
PS C:\> Test-Stream Return Value 1 Return Value 2 Return Value 3 Mandatory User Information WARNING: Warning Information Test-Stream : Error Information At line:1 char:1 + Test-Stream + ~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-Stream
PS C:\> $result = Test-Stream Mandatory User Information WARNING: Warning Information Test-Stream : Error Information At line:1 char:1 + Test-Stream + ~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Test-Stream
PS C:\> $result Return Value 1 Return Value 2 Return Value 3
PS C:\> Test-Stream Return Value 1 Return Value 2 Return Value 3 VERBOSE: Additional Information DEBUG: Developer Information Mandatory User Information Auxiliary Information