Solved

# Help redirecting powershell output to a text file

Posted on 2014-01-22
278 Views
Hello Experts,

For some reason this one is stumping me.  I have the following code that displays a message to the screen and I want it to write to a text file.

$x = 0 do { Write-Host "The count is "($x++)" right now"
} while ($x -le 100) I've tried the following:$x = 0
do
{
Write-Host "The count is "($x++)" right now" >> c:\text.txt } while ($x -le 100)

and

$x = 0 do { Out-file "The count is "($x++)" right now" | c:\text.txt
} while ($x -le 100) and$x = 0
do
{
Write-Host "The count is "($x++)" right now" | out-file c:\test.txt } while ($x -le 100)

What am I missing?
0
Question by:ndalmolin_13

LVL 18

Accepted Solution

x-men earned 500 total points
do {$x++;"$x" >> test.txt } while ($X -le 10) 0 LVL 1 Author Closing Comment That did the trick. Thanks for the quick reply. 0 LVL 18 Expert Comment$x = 0
do
{
++$x; "The count is$x right now" | Add-Content  c:\temp\rahman2.txt
} while (\$x -le 100)
0

LVL 26

Expert Comment

You can't use write-host as it doesn't return any objects. It simply sends them to the host.
0

## Featured Post

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Synchronize a new Active Directory domain with an existing Office 365 tenant
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.