In this write-up, the cmdlet “Write-Output” will be demonstrated in PowerShell.
How to Use the Cmdlet “Write-Output” in PowerShell?
As stated above, the “Write-Output” cmdlet is used for displaying the output in the PowerShell console. Its primary purpose is to send the objects to the pipeline.
Now, check out the below-provided examples for a practical demonstration of the stated cmdlet!
Example 1: Utilize the Cmdlet “Write-Output” to Write Text in PowerShell Console
To write the text in the PowerShell console, use the “Write-Output” cmdlet:
Example 2: Use the “Write-Output” Cmdlet to Display the Output of the Cmdlet Assigned Variable
Use the provided demonstration for displaying the output of the cmdlet assigned variable:
Write-Output $var
According to the above code:
- Initialize a variable “$var” variable and assign it the “Get-Service” cmdlet.
- Use the “Write-Output” cmdlet along with the “$var” assigned variable:
Example 3: Use the “Write-Output” Cmdlet to Display the Total Number of Values
To write the output and measure the objects in the console, execute the below-stated cmdlet:
In the above-illustrated code:
- Write the “Write-Output” cmdlet along with the numbers separated by commas.
- Then, add the “|” pipeline and assign the “Measure-Object” cmdlet:
Example 4: Use the “Write-Output” Cmdlet to Write Text in a PowerShell Script
This example will illustrate the procedure to write the text output in a PowerShell script with the cmdlet “Write-Output”. For that corresponding purpose, simply add the “Write-Output” cmdlet along with the desired text that needs to be displayed as an output:
That was all about the working of the “Write-Output” cmdlet in PowerShell.
Conclusion
The cmdlet “Write-Output” in PowerShell is utilized for writing objects to the pipeline. Primarily, it is considered the “go-to” command for writing output in the console. This write-up has demonstrated the cmdlet “Write-Output” in detail.