Hi, Damian Garbus here. I’m so excited that you are here. Today I want to show 6 the most basic Powershell commands for output preparing. If you learn Powershell this list will help you use more efficiently commands in your new script. In my opinion, learning PowerShell commands is like learn words in foreign languages. If you know more, you can write faster scripts and automate your job.

 

Powershell output commands

Write-Host

The basic command to print output in the Powershell console. Remember: This command does not create an Powershell object, so it’s cannot be assigned to the variable. Let’s play with this command…

Write-Host
Write-Host "Poshland"
Write-Host "Poshland" -ForegroundColor Green
$x = Write-Host "Poshland" -ForegroundColor Green
$x
(Write-Host "Poshland" -ForegroundColor Green).GetType()
powershell output commands

Read-Host

This command is not used to prepare output data from powershell scripts and functions. However, I joined it to this post because it allows interaction with the console and the Powershell script. It will help you to input some string to your script or Powershell console. You can assign the result of this command to the variable.

Read-Host "Please type your string"
$x = Read-Host "Please type your string"
$x
powershell output commands

Write-Output

This command is very similar to Write-Host but has very important deference. The result of this command can be assigned to the variable because it’s an object.

Write-Output
Write-Output -InputObject "Poshland Blog"
$x = Write-Output -InputObject "Poshland Blog"
$x
$x.GetType()
powershell output commands

Write-Verbose

Write-Verbose is a specific command very important during writing Powershell scripts and functions. It’s used when you want to print more details in result from the script but only in Verbose mode. See example:

 [cmdletbinding()]
 Param()
 Write-Verbose "My hide output only for verbose mode"
 Write-Output "Script output"
powershell output commands

Write-Warning

The next one very important command in Powershell. You can use this command in your script or function to show a warning. By default it only prints output and you cannot assign the results of this command to the variable. In the future, I will write about “try{} catch{}” commands which will allow you for more advanced use Write-Warning command.

Write-Warning -Message "My Custom Warning"
$x = Write-Warning -Message "My Custom Warning"
powershell output commands

Write-Error

Did you often see the red error in Powershell console? Write-Error command helps to prepare your custom error and display in Powershell console. Like a Write-Warning command, Write-Error also can be more advanced with “try{} catch{}” command.

Write-Error -Message "My Custom error message"
powershell output commands

Conclusion

The list above will help you prepare output in your scripts or Powershell console. You can test all the commands above just now in your Powershell console. Which of the above commands do you use most often?

Get Access to Poshland Resources for FREE!!!

Signup now and receive an email once I publish new content.

I agree to have my personal information transfered to MailChimp ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.


Damian Garbus

Hi, My name is Damian. I'm Powershell geek. Also, I love to improve my productivity and yourself development. I connected Powershell and my productivity tricks and built this blog. You can find here how to learn Powershell and use this to improve your productivity. Enjoy.

    2 replies to "6 the most basic Powershell output commands"

    • Dan Iverson

      This command is not for prepare output in your PowerShell scripts or functions.
      You may want to edit this line below Get-Input, it isn’t proper English.

    • Damian Garbus

      Hi, thank you for a comment. A moment ago I corrected the line. I hope now it’s ok.
      I’m sorry for that but English is not my native language. I’m working on it to improve my English skills.

Leave a Reply

Your email address will not be published.