Solved

Help redirecting powershell output to a text file

Posted on 2014-01-22
4
278 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
Comment Utility
do {$x++;"$x" >> test.txt } while ($X -le 10)
0
 
LVL 1

Author Closing Comment

by:ndalmolin_13
Comment Utility
That did the trick.  Thanks for the quick reply.
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
$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
Comment Utility
You can't use write-host as it doesn't return any objects. It simply sends them to the host.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.

762 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

9 Experts available now in Live!

Get 1:1 Help Now