且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

写入主机和写入输出之间的 PowerShell 区别?

更新时间:2023-11-03 09:20:40

简而言之,Write-Host 写入控制台本身.将其视为 VBScript 中的 MsgBox.另一方面,Write-Output 写入管道,因此下一个命令可以接受它作为其输入.您不需要使用 Write-Output 来编写对象,因为 Write-Output 是为您隐式调用的.

In a nutshell, Write-Host writes to the console itself. Think of it as a MsgBox in VBScript. Write-Output, on the other hand, writes to the pipeline, so the next command can accept it as its input. You are not required to use Write-Output in order to write objects, as Write-Output is implicitly called for you.

PS> Get-Service

将是相同的:

PS> Get-Service | Write-Output