Simply outputting something is PowerShell is a thing of beauty - and one its greatest strengths. For example, the common Hello, World! application is reduced to a single line:

"Hello, World!"

It creates a string object, assigns the aforementioned value, and being the last item on the command pipeline it calls the .toString() method and outputs the result to STDOUT (by default). A thing of beauty.

The other Write-* commands are specific to outputting the text to their associated streams, and have their place as such.

Answer from Goyuix on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › write-output
Write-Output (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
The Write-Output cmdlet displays the process objects in $P to the console. ... This command pipes the "test output" string to the Get-Member cmdlet, which displays the members of the System.String class, demonstrating that the string was passed ...
Top answer
1 of 7
247

Simply outputting something is PowerShell is a thing of beauty - and one its greatest strengths. For example, the common Hello, World! application is reduced to a single line:

"Hello, World!"

It creates a string object, assigns the aforementioned value, and being the last item on the command pipeline it calls the .toString() method and outputs the result to STDOUT (by default). A thing of beauty.

The other Write-* commands are specific to outputting the text to their associated streams, and have their place as such.

2 of 7
156

I think in this case you will need Write-Output.

If you have a script like

Write-Output "test1";
Write-Host "test2";
"test3";

then, if you call the script with redirected output, something like yourscript.ps1 > out.txt, you will get test2 on the screen test1\ntest3\n in the "out.txt".

Note that "test3" and the Write-Output line will always append a new line to your text and there is no way in PowerShell to stop this (that is, echo -n is impossible in PowerShell with the native commands). If you want (the somewhat basic and easy in Bash) functionality of echo -n then see samthebest's answer.

If a batch file runs a PowerShell command, it will most likely capture the Write-Output command. I have had "long discussions" with system administrators about what should be written to the console and what should not. We have now agreed that the only information if the script executed successfully or died has to be Write-Host'ed, and everything that is the script's author might need to know about the execution (what items were updated, what fields were set, et cetera) goes to Write-Output. This way, when you submit a script to the system administrator, he can easily runthescript.ps1 >someredirectedoutput.txt and see on the screen, if everything is OK. Then send the "someredirectedoutput.txt" back to the developers.

Discussions

PowerShell Write-Output: Your Friendly Output Companion
I use Write-Host because I want to watch the world burn. More on reddit.com
🌐 r/PowerShell
31
48
February 7, 2023
Write output to a file
try.. removing the outfile stuff at the end and then adding the line Write-Output $name | Out-File C:\Temp\userdevice.txt -append after and see if that works for you More on reddit.com
🌐 r/PowerShell
5
2
June 21, 2019
In this script, why is Write-Output not behaving the way I expect?
You should first decide what you want to happen. As a good rule of thumb you should use Write-Host and Out-Host only when you want to display something in the console but don't want to capture it. Write-Output writes to the Success Stream which means you can use it to save data to variables etc. If the command succeeds. This is how Out-Host and Write-Output differs $r = 'This will not be saved to $r but will be written to console' | Out-Host $r = 'This will not be saved to $r but will be written to console' | Write-Host $r = 'This will be saved to $r but not written to console' | Write-Output $r = 'This will not be saved to $r as it will fail due to' >>this<< | Write-Output Write-Output will be the default action if you do nothing. These two blocks will produce the same result. $r = 'This will be saved to $r but not written to console' $r | Write-Output $r = 'This will be saved to $r but not written to console' $r With this knowledge you should be able to decide how to output your different information. You can read more about the different streams HERE :-) More on reddit.com
🌐 r/PowerShell
12
5
June 8, 2021
Write-Host vs Write-Output in Functions?

Go right to the source.

Write-Verboseor Write-Progress for information about progress. Write-Output for stuff going to the pipeline.

If you're using v5, there's Write-Information too.

More on reddit.com
🌐 r/PowerShell
12
12
January 22, 2016
People also ask

Can Write-Output be used to write to a file?
Yes, you can redirect the output of Write-Output to a file using the redirection operator (&gt;). For example: Write-Output "Text" &gt; output.txt
🌐
sharepointdiary.com
sharepointdiary.com › sharepoint diary › powershell › how to use write-output in powershell scripts?
How to use Write-Output in PowerShell Scripts? - SharePoint Diary
How do I prevent overwriting a file?
Use the -NoClobber parameter with the Out-File cmdlet to prevent overwrites. See the Manage Overwrites section for details.
🌐
netwrix.com
netwrix.com › en › resources › blog › powershell-write-to-file
PowerShell Write to File: “Out-File” and File Output Techniques ...
🌐
PDQ
pdq.com › powershell › write-output
Write-Output - PowerShell Command | PDQ
PS C:\> Write-Output @(1,2,3) -NoEnumerate | measure Count : 1 · This command adds the NoEnumerate parameter to treat a collection or array as a single object through the pipeline. This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.PowerShell Commands
🌐
SS64
ss64.com › ps › write-output.html
Write-Output - PowerShell cmdlet
PowerShell · How-to · Write an object to the pipeline. If the command is the last command in the pipeline, the objects are displayed in the console. Syntax Write-Output [-inputObject] Object[] [CommonParameters] Key -inputObject Object The object(s) to send along the pipeline.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to use write-output in powershell scripts?
How to use Write-Output in PowerShell Scripts? - SharePoint Diary
August 10, 2025 - Write-Output is a PowerShell cmdlet that allows you to send output to the pipeline or the console. It’s the interface between your code and the user, enabling you to convey information, data, and results.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › write-host
Write-Host (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
The Write-Host cmdlet's primary purpose is to produce for-(host)-display-only output, such as printing colored text like when prompting the user for input in conjunction with Read-Host.
Find elsewhere
🌐
Netwrix
netwrix.com › en › resources › blog › powershell-write-to-file
PowerShell Write to File: “Out-File” and File Output Techniques | Netwrix
August 26, 2025 - Both the Out-File and Set-Content cmdlets in PowerShell write content to a file, but they differ in functionality. Out-File formats and outputs the data exactly as it is displayed in the console.
🌐
Adam the Automator
adamtheautomator.com › powershell-write-output
PowerShell Write-Output: Your Friendly Output Companion
April 7, 2023 - Enclosing the Write-Output command in parentheses (i.e., (Write-Output 1,2,3)) will force enumeration to happen regardless of the -NoEnumerate parameter. Another excellent use of the Write-Output cmdlet is creating a menu system with a PowerShell script that prompts the user for input.
🌐
LazyAdmin
lazyadmin.nl › home › how to use powershell write output
How to use PowerShell Write Output — LazyAdmin
February 29, 2024 - Use the Write-Output cmdlet in PowerShell to print results or echo the value of variables. Including difference between Write-Host and Write-Output
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › out-file
Out-File (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
It implicitly uses PowerShell's formatting system to write to the file. The file receives the same display representation as the terminal. This means that the output may not be ideal for programmatic processing unless all input objects are strings. Redirecting the output of a PowerShell command (cmdlet, function, script) using the redirection operator (>) is functionally equivalent to piping to Out-File with no extra parameters.
🌐
Delft Stack
delftstack.com › home › howto › powershell › write output in powershell
How to Write Output in Windows PowerShell | Delft Stack
February 2, 2024 - The first printing method in Windows PowerShell is the Write-Output cmdlet. This cmdlet is the basic syntax of printing inside our PowerShell scripting environment. We can equate it to many language’s basic printing commands such as print, and stdout.
🌐
EDUCBA
educba.com › home › data science › data science tutorials › powershell tutorial › powershell print
PowerShell print | Different Ways of Printing Output in PowerShell
March 6, 2023 - Given below are the different ways of printing output in PowerShell: 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 ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
LazyAdmin
lazyadmin.nl › home › how to output to file with powershell out-file cmdlet
How to Output to File with PowerShell Out-File — LazyAdmin
January 11, 2024 - Write your output to a file with PowerShell Out-File cmdlet, Redirect Operator or Add-Content. All options explained with examples
🌐
EDUCBA
educba.com › home › data science › data science tutorials › powershell tutorial › powershell write to console
PowerShell Write to Console | How Write to console works in PowerShell?
March 6, 2023 - Write-Output "This is a PowerShell" | Out-File C:\Temp\output.txt ... This command is useful for writing on the console where we can’t use the Write-Host like, PowerShell workflows and Azure PowerShell runbooks.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
PowerShell Test-Path
powershellfaqs.com › powershell-write-output
PowerShell Write-Output [With Examples]
October 23, 2024 - Write-Output writes the specified objects to the pipeline. If the command is the last one in the pipeline, the objects are displayed in the console. ... Now, let me show you some examples of how Write-Output can be used in PowerShell effectively.
🌐
O'Reilly
oreilly.com › library › view › windows-powershell-quick › 0596528132 › ch01s20.html
Capturing Output - Windows PowerShell Quick Reference [Book]
September 27, 2006 - Capturing OutputThere are several ways to capture the output of commands in PowerShell:$variable = <Command>Stores the objects produced by the PowerShell command into... - Selection from Windows PowerShell Quick Reference [Book]
Author   Lee Holmes
Published   2006
Pages   115
🌐
Reddit
reddit.com › r/powershell › write output to a file
r/PowerShell on Reddit: Write output to a file
June 21, 2019 -

Hi there. I have a PowerShell script that I run from our ConfigMgr server that gets me device names when someone provides me with a list of user names.

Right now the script works, but it only outputs all the info to the PowerShell window. I can't get the output to write correctly to a file. I either get just the user names or just the device names, but can't get both.

Here's my latest version of the script:

$a = Get-content "C:\Temp\users.txt"

foreach ($name in $a)

{

$name = "Corp\" + $name

"\n" + $name + "`t"; Get-CMUserDeviceAffinity -UserName "$name" | Select-Object {$_.ResourceName} -ExpandProperty ResourceName | Out-File C:\Temp\userdevice.txt -append`

}

This will write the user names to the PowerShell window and write the device names to my specified output file. That's about as close as I've got to the desired result, which is that I'd like to have each line of my result file contain:

user name [tab character] device name