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
自動變數。 如需詳細資訊,請參閱 about_Automatic_Variables。
Warning 流
Warning 數據流適用於錯誤狀況,其嚴重程度低於寫入至 Error 數據流的錯誤。 在正常情況下,這些警告不會終止執行。 警告不會寫入 $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 之間的差異在於,除非您重新導向Write-Host
數據流,Information否則也會寫入主機控制台。
Write-Information
只會寫入 Information 數據流。
Progress 流
Progress 資料流用於傳達長時間運行的命令和腳本中的進度訊息。
Write-Progress
使用 Cmdlet 明確將訊息寫入此數據流。 數據流不支援重新 Progress 導向。