Write-Output当您想在管道上发送数据,但不一定要在屏幕上显示数据时,应使用。out-default如果没有其他人首先使用它,则管道最终会将其写入。Write-Host 当您想做相反的事情时应该使用。[console]::WriteLine本质上Write-Host是幕后工作。运行此演示代码并检查结果。function Test-Output { Write-Output "Hello World"}function Test-Output2 { Write-Host "Hello World" -foreground Green}function Receive-Output { process { Write-Host $_ -foreground Yellow }}#Output piped to another function, not displayed in first.Test-Output | Receive-Output#Output not piped to 2nd function, only displayed in first.Test-Output2 | Receive-Output #Pipeline sends to Out-Default at the end.Test-Output 您需要将连接操作括在括号中,以便PowerShell在对的参数列表进行标记化之前处理该连接Write-Host,或者使用字符串插值write-host ("count=" + $count)# orwrite-host "count=$count"顺便说一句-观看Jeffrey Snover的这段视频,解释管道的工作原理。回到我开始学习PowerShell时,我发现这是关于管道如何工作的最有用的解释。