Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - how to redirect whatif output to a file?

Reply
 
Old 10-08-2006   #1 (permalink)
gaindev


 
 

how to redirect whatif output to a file?

Redirecting text output to a file works fine by using either > operator or |
out-file, but it does not seem to work if the text output is from commands
with -whatif switch.

eg: the following command will print the output on the screen instead of
writing to the file
move-item c:\temp\* d:\temp -whatif > c:\test.txt

Is there anyway around this or it's just imposible to redirect whatif output
to a file?
Any help would be appriciated!!!

gaindev
ps:i'm using PS rc2

My System SpecsSystem Spec
Old 10-08-2006   #2 (permalink)
klumsy@xtra.co.nz


 
 

Re: how to redirect whatif output to a file?

this also doesn't work

write-Host "hello" > c:\mine.txt

the reason i think is that what -whatif and write-host do is not return
anything (which is actually what gets piped or redirected), but
directly tell the console to write to the screen (or whatever host)

i can think of a couple of workarounds, but nothing that isn't a huge
amount of effort, and an ugly hack..


Karl

My System SpecsSystem Spec
Old 10-09-2006   #3 (permalink)
gaindev


 
 

Re: how to redirect whatif output to a file?

You're right. The reason could be that only objects can be redirected. But I
think the ability to redirect standard output and standard error would be
very useful.

I love the -whatif switch, and hope that they will add a "standard
simulation" to the final PowerShell

eg: 0: stardard input, 1 standard output, 2 standard error, and 3 for
"standard simulation".

"klumsy@xtra.co.nz" wrote:

> this also doesn't work
>
> write-Host "hello" > c:\mine.txt
>
> the reason i think is that what -whatif and write-host do is not return
> anything (which is actually what gets piped or redirected), but
> directly tell the console to write to the screen (or whatever host)
>
> i can think of a couple of workarounds, but nothing that isn't a huge
> amount of effort, and an ugly hack..
>
>
> Karl
>
>

My System SpecsSystem Spec
Old 10-09-2006   #4 (permalink)
klumsy@xtra.co.nz


 
 

Re: how to redirect whatif output to a file?

for powershell analyzer, i'll have some cmdlets that can capture the
standard output and allow you acess to it for this very purpose

My System SpecsSystem Spec
Old 10-09-2006   #5 (permalink)
James Truher


 
 

Re: how to redirect whatif output to a file?

this is correct - there are certain write operations that bypass the entire
result pipeline and make direct calls to the powershell.exe host
application.

write-progress
write-warning
write-verbose
write-debug
write-host

All these cmdlets do not output to the results stream and therefore aren't
redirectable. The **only** way to capture this output is with the
transcript command

PS> start-transcript zap
Transcript started, output file is zap
PS> ps|stop-process -whatif
What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
What if: Performing operation "Stop-Process" on Target "agent (2476)".
....
What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
PS> stop-transcript
Transcript stopped, output file is C:\zap
PS> cat zap
**********************
Windows PowerShell Transcript Start
Start time: 20061009113745
Username : REDMOND\jimtru
Machine : JIMTRUD4 (Microsoft Windows NT 5.1.2600 Service Pack 2)
**********************
Transcript started, output file is zap
PS> ps|stop-process -whatif
What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
What if: Performing operation "Stop-Process" on Target "agent (2476)".
....
What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
PS> stop-transcript
**********************
Windows PowerShell Transcript End
End time: 20061009113802
**********************

--
--
James Truher [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"gaindev" <gaindev@discussions.microsoft.com> wrote in message
news248FD7A-FFB1-4EB2-ADEE-1CBC101BFE6D@microsoft.com...
> Redirecting text output to a file works fine by using either > operator or
> |
> out-file, but it does not seem to work if the text output is from commands
> with -whatif switch.
>
> eg: the following command will print the output on the screen instead of
> writing to the file
> move-item c:\temp\* d:\temp -whatif > c:\test.txt
>
> Is there anyway around this or it's just imposible to redirect whatif
> output
> to a file?
> Any help would be appriciated!!!
>
> gaindev
> ps:i'm using PS rc2



My System SpecsSystem Spec
Old 10-10-2006   #6 (permalink)
gaindev


 
 

Re: how to redirect whatif output to a file?

thanks for clearing this up!
cheers

"James Truher" wrote:

> this is correct - there are certain write operations that bypass the entire
> result pipeline and make direct calls to the powershell.exe host
> application.
>
> write-progress
> write-warning
> write-verbose
> write-debug
> write-host
>
> All these cmdlets do not output to the results stream and therefore aren't
> redirectable. The **only** way to capture this output is with the
> transcript command
>
> PS> start-transcript zap
> Transcript started, output file is zap
> PS> ps|stop-process -whatif
> What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
> What if: Performing operation "Stop-Process" on Target "agent (2476)".
> ....
> What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
> What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
> PS> stop-transcript
> Transcript stopped, output file is C:\zap
> PS> cat zap
> **********************
> Windows PowerShell Transcript Start
> Start time: 20061009113745
> Username : REDMOND\jimtru
> Machine : JIMTRUD4 (Microsoft Windows NT 5.1.2600 Service Pack 2)
> **********************
> Transcript started, output file is zap
> PS> ps|stop-process -whatif
> What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
> What if: Performing operation "Stop-Process" on Target "agent (2476)".
> ....
> What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
> What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
> PS> stop-transcript
> **********************
> Windows PowerShell Transcript End
> End time: 20061009113802
> **********************
>
> --
> --
> James Truher [MSFT]
> Windows PowerShell Development
> Microsoft Corporation
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "gaindev" <gaindev@discussions.microsoft.com> wrote in message
> news248FD7A-FFB1-4EB2-ADEE-1CBC101BFE6D@microsoft.com...
> > Redirecting text output to a file works fine by using either > operator or
> > |
> > out-file, but it does not seem to work if the text output is from commands
> > with -whatif switch.
> >
> > eg: the following command will print the output on the screen instead of
> > writing to the file
> > move-item c:\temp\* d:\temp -whatif > c:\test.txt
> >
> > Is there anyway around this or it's just imposible to redirect whatif
> > output
> > to a file?
> > Any help would be appriciated!!!
> >
> > gaindev
> > ps:i'm using PS rc2

>
>
>

My System SpecsSystem Spec
Old 10-10-2006   #7 (permalink)
klumsy@xtra.co.nz


 
 

Re: how to redirect whatif output to a file?

start-transcript - nice

My System SpecsSystem Spec
Old 10-11-2006   #8 (permalink)
/\/\o\/\/ [MVP]


 
 

Re: how to redirect whatif output to a file?

another workaround would be, start another PowerShell for it ;-)

powershell -NoProfile -command move-item c:\temp\* d:\temp -whatif >
c:\test.txt

Greeting /\/\o\/\/

"klumsy@xtra.co.nz" wrote:

> start-transcript - nice
>
>

My System SpecsSystem Spec
Old 10-11-2006   #9 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: how to redirect whatif output to a file?

Jim,

Wasn't it originally intended that these actually be _streams_ that
terminated in the console - progress, warning, verbose, and debug streams,
which along with output and error would get written to the host if not
otherwise consumed?

"James Truher" <jimtru@news.microsoft.com> wrote in message
news:uPIpwJ96GHA.3452@TK2MSFTNGP05.phx.gbl...
> this is correct - there are certain write operations that bypass the
> entire result pipeline and make direct calls to the powershell.exe host
> application.
>
> write-progress
> write-warning
> write-verbose
> write-debug
> write-host
>
> All these cmdlets do not output to the results stream and therefore aren't
> redirectable. The **only** way to capture this output is with the
> transcript command
>
> PS> start-transcript zap
> Transcript started, output file is zap
> PS> ps|stop-process -whatif
> What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
> What if: Performing operation "Stop-Process" on Target "agent (2476)".
> ...
> What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
> What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
> PS> stop-transcript
> Transcript stopped, output file is C:\zap
> PS> cat zap
> **********************
> Windows PowerShell Transcript Start
> Start time: 20061009113745
> Username : REDMOND\jimtru
> Machine : JIMTRUD4 (Microsoft Windows NT 5.1.2600 Service Pack 2)
> **********************
> Transcript started, output file is zap
> PS> ps|stop-process -whatif
> What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
> What if: Performing operation "Stop-Process" on Target "agent (2476)".
> ...
> What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
> What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
> PS> stop-transcript
> **********************
> Windows PowerShell Transcript End
> End time: 20061009113802
> **********************
>
> --
> --
> James Truher [MSFT]
> Windows PowerShell Development
> Microsoft Corporation
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "gaindev" <gaindev@discussions.microsoft.com> wrote in message
> news248FD7A-FFB1-4EB2-ADEE-1CBC101BFE6D@microsoft.com...
>> Redirecting text output to a file works fine by using either > operator
>> or |
>> out-file, but it does not seem to work if the text output is from
>> commands
>> with -whatif switch.
>>
>> eg: the following command will print the output on the screen instead of
>> writing to the file
>> move-item c:\temp\* d:\temp -whatif > c:\test.txt
>>
>> Is there anyway around this or it's just imposible to redirect whatif
>> output
>> to a file?
>> Any help would be appriciated!!!
>>
>> gaindev
>> ps:i'm using PS rc2

>
>



My System SpecsSystem Spec
Old 10-11-2006   #10 (permalink)
James Truher


 
 

Re: how to redirect whatif output to a file?

that was the *intention*, but as Jeffrey often says:
"To ship is to choose"



--
--
James Truher [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:%23DZr3cV7GHA.3604@TK2MSFTNGP02.phx.gbl...
> Jim,
>
> Wasn't it originally intended that these actually be _streams_ that
> terminated in the console - progress, warning, verbose, and debug streams,
> which along with output and error would get written to the host if not
> otherwise consumed?
>
> "James Truher" <jimtru@news.microsoft.com> wrote in message
> news:uPIpwJ96GHA.3452@TK2MSFTNGP05.phx.gbl...
>> this is correct - there are certain write operations that bypass the
>> entire result pipeline and make direct calls to the powershell.exe host
>> application.
>>
>> write-progress
>> write-warning
>> write-verbose
>> write-debug
>> write-host
>>
>> All these cmdlets do not output to the results stream and therefore
>> aren't redirectable. The **only** way to capture this output is with
>> the transcript command
>>
>> PS> start-transcript zap
>> Transcript started, output file is zap
>> PS> ps|stop-process -whatif
>> What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
>> What if: Performing operation "Stop-Process" on Target "agent (2476)".
>> ...
>> What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
>> What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
>> PS> stop-transcript
>> Transcript stopped, output file is C:\zap
>> PS> cat zap
>> **********************
>> Windows PowerShell Transcript Start
>> Start time: 20061009113745
>> Username : REDMOND\jimtru
>> Machine : JIMTRUD4 (Microsoft Windows NT 5.1.2600 Service Pack 2)
>> **********************
>> Transcript started, output file is zap
>> PS> ps|stop-process -whatif
>> What if: Performing operation "Stop-Process" on Target "AdtAgent (1720)".
>> What if: Performing operation "Stop-Process" on Target "agent (2476)".
>> ...
>> What if: Performing operation "Stop-Process" on Target "wmiprvse (2552)".
>> What if: Performing operation "Stop-Process" on Target "wmiprvse (3800)".
>> PS> stop-transcript
>> **********************
>> Windows PowerShell Transcript End
>> End time: 20061009113802
>> **********************
>>
>> --
>> --
>> James Truher [MSFT]
>> Windows PowerShell Development
>> Microsoft Corporation
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "gaindev" <gaindev@discussions.microsoft.com> wrote in message
>> news248FD7A-FFB1-4EB2-ADEE-1CBC101BFE6D@microsoft.com...
>>> Redirecting text output to a file works fine by using either > operator
>>> or |
>>> out-file, but it does not seem to work if the text output is from
>>> commands
>>> with -whatif switch.
>>>
>>> eg: the following command will print the output on the screen instead of
>>> writing to the file
>>> move-item c:\temp\* d:\temp -whatif > c:\test.txt
>>>
>>> Is there anyway around this or it's just imposible to redirect whatif
>>> output
>>> to a file?
>>> Any help would be appriciated!!!
>>>
>>> gaindev
>>> ps:i'm using PS rc2

>>
>>

>
>



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Redirect Sound Card Output Vista hardware & devices
Redirect all output PowerShell
How can I redirect output from Invoke-Expression ? PowerShell
redirect unicode format output PowerShell
write whatif output to file PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46