Solved

# Help redirecting powershell output to a text file

Posted on 2014-01-22
283 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
ID: 39800127
do {$x++;"$x" >> test.txt } while ($X -le 10) 0 LVL 1 Author Closing Comment ID: 39800165 That did the trick. Thanks for the quick reply. 0 LVL 19 Expert Comment ID: 39800177$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

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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Starting up a Project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…