EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell print
Secondary Sidebar
PowerShell Tutorial
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell print

PowerShell print

Introduction to PowerShell print

Writing output to the console or a file is an important requirement of any language. The output can generally be a single line, multi-lines or an expression or result of an expression. Printing values can also be used for debugging or as part of an error handling mechanism. There are multiple ways of printing output in PowerShell. Some of the ways in PowerShell to print are Write-Output, Write-Host, Write-Verbose, Write-Warning and Write-Error.

Different Ways of Printing Output in PowerShell

Given below are the different ways of printing output in PowerShell:

1. Write-Output

The first method of printing output is using the Write-Output cmdlet. This cmdlet is used to pass objects in the pipeline to the successive commands. In case of the command being last, the final object is written to the console. To pass on error objects, Write-Error cmdlet is used.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,650 ratings)

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Write-Output [-InputObject] <PSObject[]> [-NoEnumerate] [<CommonParameters>]

Parameters:

  • -InputObject: This denotes the objects that should be passed through the pipeline. It can be an expression, a variable of objects or an expression. The datatype of this parameter is PSObject[]. Its default value is none. It accepts pipeline input but doesn’t accept wildcard characters.
  • -NoEnumerate: The write-output cmdlet by default enumerates the output. To avoid that, this parameter is used. The datatype of this parameter is Switch. None is the default value. It doesn’t accept pipeline input, as well as wildcard characters, which are also not permitted.

Example:

Code:

Write-Host "Demo of write host cmdlet" -ForegroundColor Green
$test= Get-Process
Write-Host "Printing a variable" -ForegroundColor Green
Write-Output $test
Write-Host "Passing output to another cmdlet through pipeline" -ForegroundColor Green
Write-Output "sample output" | Get-Member
Write-Host "Example of enumerate and no enumerate" -ForegroundColor Green
Write-Output 10,20,30 | Measure-Object
Write-Output 10,20,30 -NoEnumerate | Measure-Object

Output:

PowerShell print 1

2. Write-Host

The primary usage of this cmdlet is to display the output in different colours. This works along with the read-host cmdlet, which retrieves the input from the user. This cmdlet uses the ToString() method to generate and write the output to the console. We can specify both the text color and background color of the output using the foreground and background parameters respectively. To separate the various objects in the output, a separator parameter is present as part of the cmdlert. There are two variables; $informationpreference and $Informationaction parameters that are associated with this parameter, but they don’t affect the output.

Parameters:

  • -BackgroundColor: This denotes the color of the background. There is no default color. Some of the values are grey, green, blue, red, white, dark green, dark blue and magneta. The datatype of this parameter is console color. It doesn’t accept pipeline input, and wild card characters are also not permitted.
  • -Foregroundcolor: This denotes the color of the text. There is no default color. Some of the values are grey, green, blue, red, white, dark green, dark blue and magneta. The datatype of this parameter is console color. It doesn’t accept pipeline input, and wild card characters are also not permitted.
  • -NoNewLine: This denotes that all the output is written on the same line, and no newline is inserted between the outputs. The data type of the parameter is a switch. The default value is none. It doesn’t accept pipeline input, and wild card characters are also not permitted.
  • -Object: This denotes the object to be written as output. The data type of this parameter is an object. The alias for this parameter is Msg and message. This is a mandatory parameter. The default value is none. It accepts pipeline input, whereas wild card characters are not permitted.
  • -Separator: This denotes the separator to be inserted between objects. The data type of this parameter is an object. The default value is none. It doesn’t accept pipeline input, and wild card characters are not permitted.

Example:

Code:

Write-Host "Demo of write-host"
Write-Host "printing in same line example" -NoNewline
Write-Host "test of second line"
Write-Host "example with separator"
Write-Host (20,49,69,80,10,128) -Separator ", +4= "
Write-Host "Example of background colours"
Write-Host (21,41,62,81,110,121) -Separator ", ->> " -ForegroundColor Blue -BackgroundColor White
Write-Host "Iam vignesh, from chennai" -ForegroundColor DarkGreen -BackgroundColor white
Write-Host "Preventing from printing"
Write-Host "this wont be displayed" -InformationAction Ignore
Write-Host "it wont be available on screen" 6>$null

Output:

PowerShell print 2

3. Write-Debug

This is used for printing debug message in the console from a script or command. By default, the messages are not displayed but can be displayed whenever needed using the $debugPreference variable.

Syntax:

Write-Debug [-Message] <String> [<CommonParameters>]

Parameters:

  • -Message: This denotes the debug message that needs to be displayed. The data type of this parameter is a string. This is a mandatory parameter. The alias of this parameter is msg. None is its default value. It accepts pipeline input, but wild card characters are not permitted.

Example:

Code:

Write-Host "Demo of write-debug"
Write-Debug "This wont be printed"
Write-Debug "my name is vignesh"
Write-Host "Changing the value of debug preference variable" -ForegroundColor Green
Write-Host "Current value is" -ForegroundColor Green
$DebugPreference
Write-Debug "wont print this on console"
$DebugPreference = "Continue"
Write-Debug "now this will be displayed"

Output:

Write-Debug

4. Write-Verbose

The Write-Verbose cmdlet writes text to the verbose message stream in PowerShell. Typically, the verbose message stream is employed to deliver more thorough information about command processing. By default, the verbose message stream isn’t displayed but can be displayed by changing the worth of the $VerbosePreference variable or using the Verbose common parameter in any command.

Syntax:

Write-Verbose [-Message] <String> [<CommonParameters>]

Parameters:

  • -Message: This denotes the message that needs to be displayed. This is a mandatory parameter. The data type of this parameter is a string. The alias is msg. The default value is none. It accepts pipeline input, but wild card characters are not permitted.

Example:

Code:

Write-Host "Example of verbose command"
Write-Verbose -Message "Searching the error in Event viewer."
Write-Verbose -Message "Searching the error in Event viewer." -Verbose

Output:

Write-Verbose

Conclusion – PowerShell print

Thus, the article covered in detail about printing in PowerShell. It explained in detail about the various ways in which output can be printed along with appropriate examples.

Recommended Articles

This is a guide to PowerShell print. Here we discuss the introduction and different ways of printing output in PowerShell. You may also have a look at the following articles to learn more –

  1. PowerShell Sleep
  2. PowerShell SubString
  3. PowerShell not like
  4. Else If in PowerShell
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more