Solved

Help redirecting powershell output to a text file

Posted on 2014-01-22
4
279 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
Comment
Question by:ndalmolin_13
4 Comments
 
LVL 18

Accepted Solution

by:
x-men earned 500 total points
ID: 39800127
do {$x++;"$x" >> test.txt } while ($X -le 10)
0
 
LVL 1

Author Closing Comment

by:ndalmolin_13
ID: 39800165
That did the trick.  Thanks for the quick reply.
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
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

by:pony10us
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now