Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Help redirecting powershell output to a text file

Posted on 2014-01-22
Medium Priority
301 Views
Last Modified: 2014-01-22
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
4 Comments

LVL 18

Accepted Solution

x-men earned 2000 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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
###### Suggested Courses
Course of the Month12 days, 1 hour left to enroll

#### 916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.