about_Output_Streams

簡短描述

說明 PowerShell 中輸出資料流的可用性和用途。

詳細描述

PowerShell 提供多個輸出數據流。 數據流會為不同類型的訊息提供通道。 您可以使用相關聯的 Cmdlet 或重新導向來寫入這些數據流。 如需詳細資訊,請參閱 about_Redirection

PowerShell 支援下列輸出數據流。

流# 描述 中引進 寫入 Cmdlet
1 Success PowerShell 2.0 Write-Output
2 Error PowerShell 2.0 Write-Error
3 Warning PowerShell 2.0 Write-Warning
4 Verbose PowerShell 2.0 Write-Verbose
5 Debug PowerShell 2.0 Write-Debug
6 Information PowerShell 5.0 Write-Information
n/a Progress PowerShell 2.0 Write-Progress

注意

數據流不支援重新 Progress 導向。

Success 流

數據流 Success 是一般、成功結果的預設數據流。 Write-Output使用 Cmdlet 明確將物件寫入此數據流。 此數據流用於透過PowerShell管線傳遞物件。 數據流 Success 會連線到 原生應用程式的 stdout 數據流。

Error 流

數據流 Error 是錯誤結果的預設數據流。 Write-Error使用 Cmdlet 明確寫入此數據流。 數據流 Error 會連線到 原生應用程式的 stderr 數據流。 在大部分情況下,這些錯誤可能會終止執行管線。 Error寫入此數據流的 $Error s 也會新增至自動變數。 如需詳細資訊,請參閱 about_Automatic_Variables

Warning 流

數據流 Warning 適用於錯誤狀況,其嚴重程度低於寫入數據流的錯誤 Error 。 在正常情況下,這些警告不會終止執行。 Warning不會寫入 $Error 至自動變數。 Write-Warning使用 Cmdlet 明確寫入此數據流。

Verbose 流

數據流 Verbose 適用於可協助使用者在以互動方式或從腳本執行時對命令進行疑難解答的訊息。 Write-Verbose使用 Cmdlet 明確將訊息寫入此數據流。 許多 Cmdlet 提供詳細資訊輸出,有助於瞭解 Cmdlet 的內部運作。 只有在您使用 -Verbose 通用參數時,才會輸出詳細資訊訊息。 如需詳細資訊,請參閱 about_CommonParameters

Debug 流

數據流 Debug 用於協助腳本者瞭解其程式代碼失敗的原因的訊息。 Write-Debug使用 Cmdlet 明確寫入此數據流。 只有在您使用 -Debug 通用參數時,偵錯訊息才會輸出。 如需詳細資訊,請參閱 about_CommonParameters

Debug 訊息適用於腳本和 Cmdlet 開發人員,而不是終端使用者。 這些偵錯訊息可以包含深入疑難解答所需的內部詳細數據。

Information 流

數據流 Information 旨在提供訊息,協助使用者瞭解腳本正在執行的動作。 開發人員也可以使用它做為透過PowerShell傳遞資訊的額外數據流。 開發人員可以標記數據流數據,並具有該數據流的特定處理。 Write-Information使用 Cmdlet 明確寫入此數據流。

Write-Host 也會寫入 Information 數據流。 Cmdlet 之間的差異在於,除非您重新導向Information數據流,Write-Host否則也會寫入主機控制台。 Write-Information 只會寫入 Information 數據流。

Progress 流

數據流 Progress 用於在較長執行命令和腳本中通訊進度的訊息。 Write-Progress使用 Cmdlet 明確將訊息寫入此數據流。 數據流不支援重新 Progress 導向。

另請參閱