To print output to the console in PowerShell, you can use the Write-Output
cmdlet. This cmdlet is used to write objects to the pipeline, which can then be displayed on the screen or redirected to a file or another cmdlet.
Here's an example of using the Write-Output
cmdlet to print output to the console:
$message = "Hello World"
Write-Output $message
In this example, the Write-Output
cmdlet is used to print the value of the $message
variable to the console. The code will output the string Hello World
to the console.
You can also use the Write-Output
cmdlet to print multiple values to the console by separating them with a comma.
Here's an example:
$message1 = "Hello World"
$message2 = "How are you?"
Write-Output $message1, $message2
In this example, the Write-Output
cmdlet is used to print the values of the $message1
and $message2
variables to the console. The code will output the strings "Hello World" and "How are you?" to the console, separated by a space.
The Write-Output
cmdlet is a useful tool for printing output to the console in PowerShell.
Related tutorials curated for you
How to use ErrorAction in PowerShell
How to use String Contains in PowerShell
How to list all installed modules in PowerShell
How to trim text in PowerShell
How to find the Windows version from the PowerShell command line
How to get the string length of a variable in PowerShell
Switch statement in PowerShell
What is PowerShell Grep?
What is Write-Host in PowerShell?
How to sort in PowerShell
How to unzip a file in Powershell
What is `ls` for PowerShell?