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
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
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
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.
🌐
Netwrix
netwrix.com › en › resources › blog › powershell-write-to-file
PowerShell Write to File: “Out-File” and File Output Techniques | Netwrix
August 26, 2025 - Set-Content writes the data as plain text, without any formatting. ... Using PowerShell, you can export just the error messages to a log file. The 2> redirection operator is used to redirect the error stream to a file. Here is how you can run a command and redirect error messages to a log file. ... This command will only log the error messages, if any, to C:\Temp\error_log.txt and ignore other outputs.
Find elsewhere
🌐
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.
🌐
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.
🌐
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
🌐
Breakingpwsh
breakingpwsh.com › articles › write-host-vs-write-output-the-final-argument
breakingpwsh.com - Write-Host vs Write-Output - The Final Argument
That Write-Output was the only correct way to show text output to the console. Congrats, you have found the most pointless PowerShell argument that exists.
🌐
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.
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.

🌐
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

🌐
Windows OS Hub
woshub.com › write-output-log-files-powershell
Writing Output to Log Files in PowerShell Script | Windows OS Hub
March 3, 2025 - Here are examples of three different commands that add a new line with the output of a PowerShell command to the log file. Write-Output "Files are successfully created in $env:computername" >> C:\PS\Logs\TestLog.txt Add-Content -Path C:\PS\Logs\TestLog.txt -Value "Files are successfully created in $env:computername" "Files are successfully created in $env:computername" | Out-File -FilePath C:\PS\Logs\TestLog.txt –Append # The -Append parameter is used to add data to a file without overwriting existing data.