![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 news 248FD7A-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 Specs![]() |
| | #6 (permalink) |
| | 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 > news 248FD7A-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 Specs![]() |
| | #7 (permalink) |
| | Re: how to redirect whatif output to a file? start-transcript - nice |
My System Specs![]() |
| | #8 (permalink) |
| | 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 Specs![]() |
| | #9 (permalink) |
| | 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 > news 248FD7A-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 Specs![]() |
| | #10 (permalink) |
| | 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 >> news 248FD7A-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 Specs![]() |
![]() |
| 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 | |||