We have the following 7 types of streams in Powershell.
- Write-Output
- Write-Host
- Write-Debug
- Write-Verbose
- Write-Error
- Write-Warning
- Write-Information(introduced in v5.0)
We will take a look at each of them below:-
- Write-Output - It is used to write the result to the output stream. In the example below, we can see that since the result from first cmdlet is passed to the second cmdlet, the filter condition is applied and "Roshan" is filtered out due to it's length.
- Write-Host - It sends the output directly to the console. Due to this, it cannot be piped with other cmdlets. Here, in the example below, continuing from the first example, we can see that "Roshan" is displayed on the screen because it is directly written on the console and the filter condition is not applied on it.
- Write-Debug - It is used to write debug information on the console. By default, the $DebugPreference is set to SilentlyContinue. So, by default the message will not be displayed on the console. If we set the $DebugPreference to Continue, the debug messages will start appearing on the screen.
- Write-Verbose - This cmdlet is used to provide additional information about the command that is being debugged. Similar to Write-Debug, this cmdlet has $VerbosePreference which needs to be set to Continue for the messages to be displayed on the screen.
- Write-Error - It writes the result to the Error stream.
- Write-Warning - It writes a warning message. Similar to Write-Debug and Write-Verbose, it has $WarningPreference which needs to be set to Continue for it to be displayed on the console.
- Write-Information - It displays additional information about the execution of any script. Depending on the $InformationPreference, it displays those messages during the execution of the scripts.
Hope this gives you a head start on the various available streams in Powershell.
No comments:
Post a Comment