PowerShell 管道:如何串联 Cmdlet
1. 管道基础
自 20 世纪 70 年代的 Unix 和 C 编程语言以来,操作系统将计算机的输入和输出抽象为标准流。常见的标准流有标准输入(stdin)、标准输出(stdout)和标准错误(stderr)。PowerShell 在此基础上进行了扩展,拥有六个输出流,具体如下表所示:
| 流编号 | 描述 | Cmdlet | 通用参数 |
| ---- | ---- | ---- | ---- |
| 1 | 成功 | Write-Output | 无 - 这是默认输出 |
| 2 | 错误 | Write-Error | -ErrorAction 和 -ErrorVariable |
| 3 | 警告 | Write-Warning | -WarningAction 和 -WarningVariable |
| 4 | 详细 | Write-Verbose | -Verbose |
| 5 | 调试 | Write-Debug | -Debug |
| 6 | 信息 | Write-Information | -InformationAction 和 -InformationVariable |
PowerShell 管道将流 1(成功输出)的内容从一个 Cmdlet 传递到管道中的下一个 Cmdlet。管道可以由一个或多个 PowerShell Cmdlet 组成,用管道字符(|)分隔。即使只有一个 Cmdlet,它也是管道的一部分,并且每个管道末尾都有隐式的 Out-Default | Out-Host ,用于将 Cmdlet 的
超级会员免费看
订阅专栏 解锁全文
74

被折叠的 条评论
为什么被折叠?



