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
Writes the specified objects to the pipeline. If Write-Output is the last command in the pipeline, the objects are displayed in the console. Write-Output sends objects to the primary pipeline, also known as the success stream.
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
Powershell: Write-Output in Function with Return Value
I’ve narrowed down a problem I’ve asked about before here so hopefully this will bring about the best answer. My issue is that I need to use Write-Output in many places throughout my script however it will not always work. This occurs when I attempt to use Write-Output in a function that ... More on community.spiceworks.com
🌐 community.spiceworks.com
17
3
January 31, 2019
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
Redirect write-host outputs to text file
Hello, I am trying to export the write-host output to text file, but it’s not happening, can someone please help write-host “hello world” | out-file .\log.txt In a script, I want to save all the results of write-host commands .\test.ps1 3>&1 2>&1 4>&1 6>&1|Out-File .\log.txt The above ... More on forums.powershell.org
🌐 forums.powershell.org
8
0
April 9, 2021
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 (>). For example: Write-Output "Text" > 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
The Write-Output cmdlet sends the specified object down the pipeline to the next command. If the command is the last command in the pipeline, the object is displayed in the console.
🌐
SS64
ss64.com › ps › write-output.html
Write-Output - PowerShell cmdlet
For example, Get-Process | write-output is equivalent to get-process ... PS C:\> Function Test-function { Write-output "here is some text" } PS C:\> Test-function here is some text
🌐
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
Find elsewhere
🌐
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 - We can also store the string inside the variable and write the output. $str = "This is a PowerShell Output" Write-Output $str
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Netwrix
netwrix.com › en › resources › blog › powershell-write-to-file
PowerShell Write to File: “Out-File” and File Output Techniques | Netwrix
August 26, 2025 - With PowerShell pipe output to file functionality, you can take command output and immediately save it to a text file for later analysis. ... To write a string using the PowerShell write string to file method, such as adding “Hello, World!” to a text file named “Test” at the C:\Temp location, use the following cmdlet:
🌐
Adam the Automator
adamtheautomator.com › powershell-write-output
PowerShell Write-Output: Your Friendly Output Companion
April 7, 2023 - In addition to displaying the output in the console, you can use the Write-Output command to send the object to another command for further processing. How? By using the pipeline operator (|). Pipelining makes Write-Output a handy and versatile command for automation and system management tasks. Related:Getting to Know the PowerShell Pipeline and Creating Functions
🌐
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 - When running a script, you can insert Write-Output statements to display the current value of variables or the flow of execution. This makes it easier to identify where issues might be occurring.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › out-file
Out-File (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
The Out-File cmdlet sends output to a file. It implicitly uses PowerShell's formatting system to write to the file. The file receives the same display representation as the terminal.
🌐
Breakingpwsh
breakingpwsh.com › articles › write-host-vs-write-output-the-final-argument
breakingpwsh.com - Write-Host vs Write-Output - The Final Argument
The advantage of Write-Output is that the text can be piped to the "stream" or "pipeline" and used by a cmdlet further in the pipeline. Maybe even passed to another script. Thats the big difference there - -Host is for humans, -Output is for the powershell host.
Top answer
1 of 16
1

Yes that is what Write-Output does. It writes output directly to the Output stream, which other parts of the script can pick up on. It is somewhat synonymous with return in this regard.

Depending on what your requirements are there are a number of different streams you could write to.

Write-Error

Write-Warning

Write-Verbose (as you have already picked up on)

Write-Debug

Write-Information

Write-Host (Gets puppies killed though Write-Host Considered Harmful | Jeffrey Snover's blog )

So maybe Write-Information is a better fit. It works in a very similar way to Write-Host except without the stupid colours that people insist on using and you can redirect it off elsewhere if you personally don’t want to read it (I rarely do and for me verbose is usually much more useful if something is going wrong anyway).

2 of 16
3

I’ve narrowed down a problem I’ve asked about before here so hopefully this will bring about the best answer. My issue is that I need to use Write-Output in many places throughout my script however it will not always work. This occurs when I attempt to use Write-Output in a function that returns a value. So, here are two examples.

This would work:

function hello{
	for ($i=0;$i-lt5;$i++){
		Write-Output "Hello World $i"
	}
}
hello

#Output

Hello World 0
Hello World 1
Hello World 2
Hello World 3
Hello World 4

This would NOT work;

function getOut ($number){
	if ($number -eq 1){
		Write-Output "Uh oh"
		$retVal = "false"
	}
	else{
		Write-Output Woo
		$retVal = "true"
	}
	return $retVal
}
function hello{
	$boolQ = 0
	$outPut = getOut $boolQ
	Write-Output "Finished!"
}
hello

#Output

Finished!

Now, I’m still unsure to the exact cause but from testing, it’s clear that functions that are called in this sort of style:

$val = myFunction

don’t seem to like Write-Output. Now I guess the reason is because the pipe is full with $val or something and I imagine many will suggest Write-Verbose but I honestly am just not a fan of the "Verbose: " part. I’m also writing this to a log using Add-Content (I find Out-File a bit more clunky and I don’t need to read and write at the same time so I’m happy using Add-Content).

I would be happy using verbose however I really need the "Verbose: " bit gone.

🌐
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
🌐
Practical 365
practical365.com › home › powershell › practical powershell: output and logging
Practical PowerShell: Output and Logging | Practical365
September 3, 2024 - I occasionally use these cmdlets to keep a record of everything I do in customer environments. While simple, it is an unstructured output that is hard to process further. Since the early days of PowerShell, the community encouraged the usage of the Write-Output cmdlet over cmdlets such as Write-Host.
🌐
Dotnet Helpers
dotnet-helpers.com › home › powershell › difference between write-host and write-output in powershell
Difference between write-host and write-output in powershell | PowerShell, Powershell demo
August 26, 2024 - In simpler, if you possibly want to write data to the screen, but also want the data to be passed down the pipeline to further commands, then use Write-Output. Write-Host does not output data to PowerShell Object flow Engine but rather, as the name implies, writes directly to the host and sends nothing to the PowerShell engine to be forwarded to commands later in the pipeline.
🌐
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

🌐
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 - There are a couple of ways to write the output of PowerShell to a file. The most common ways are to use the Out-File cmdlet or the redirection operator >. Other options are to use the Set-Content and Add-Content cmdlet.
🌐
PowerShell Forums
forums.powershell.org › powershell help
Redirect write-host outputs to text file - PowerShell Help - PowerShell Forums
April 9, 2021 - Hello, I am trying to export the write-host output to text file, but it’s not happening, can someone please help write-host “hello world” | out-file .\log.txt In a script, I want to save all the results of write-hos…
Top answer
1 of 6
307

Write-Output should be used when you want to send data on in the pipeline, but not necessarily want to display it on screen. The pipeline will eventually write it to Out-Default if nothing else uses it first.

Write-Host should be used when you want to do the opposite.

[console]::WriteLine is essentially what Write-Host is doing behind the scenes.

Run this demonstration code and examine the result.

function Test-Output {
    Write-Output "Hello, World!"
}

function Test-Output2 {
    Write-Host "Hello, World!" -foreground Green
}

function Receive-Output {
    process { Write-Host $_ -foreground Yellow }
}

# Output is piped to another function, not displayed in the first.
Test-Output | Receive-Output

# Output us not piped to the 2nd function, only displayed in the first.
Test-Output2 | Receive-Output

# The pipeline sends to Out-Default at the end.
Test-Output

You'll need to enclose the concatenation operation in parentheses, so that PowerShell processes the concatenation before tokenizing the parameter list for Write-Host, or use string interpolation

Write-Host ("count=" + $count)
# or
Write-Host "count=$count"

BTW - Watch this video of Jeffrey Snover explaining how the pipeline works. Back when I started learning PowerShell, I found this to be the most useful explanation of how the pipeline works.

2 of 6
33

Apart from what Andy mentioned, there is another difference which could be important: Write-Host directly writes to the host and returns nothing, meaning that you can't redirect the output, e.g., to a file.

---- script a.ps1 ----
Write-Host "hello"

Now run in PowerShell:

PS> .\a.ps1 > someFile.txt
hello
PS> type someFile.txt
PS>

As seen, you can't redirect them into a file. This maybe surprising for someone who are not careful.

But if switched to use Write-Output instead, you'll get redirection working as expected.