ndalmolin_13
asked on
Help redirecting powershell output to a text file
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$x = 0
do
{
++$x;
"The count is $x right now" | Add-Content c:\temp\rahman2.txt
} while ($x -le 100)
do
{
++$x;
"The count is $x right now" | Add-Content c:\temp\rahman2.txt
} while ($x -le 100)
You can't use write-host as it doesn't return any objects. It simply sends them to the host.
ASKER