Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

"@Echo" behavior in PS scripts

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-03-2008   #1 (permalink)
Martin Zugec
Guest


 

"@Echo" behavior in PS scripts

Hi everyone,

writing my first script after 3 years I wanted to implement also
different logs in it - event log support, overview log and debug log (this
script will run as scheduled task).

Event log and overview log are not problem. For debug log, I wanted to save
full output to log file, so in case of any problems I could just check this
"last session" log file.

To my surprise I realized PowerShell behaves like "@Echo Off" in old
batches - is there any way to switch it full output??

Thanks,
Martin


My System SpecsSystem Spec
Old 07-03-2008   #2 (permalink)
Martin Zugec
Guest


 

Re: "@Echo" behavior in PS scripts

BTW idea behind is pretty simply, I just want to use Start-Transcript to
create debug log of whole script execution
In batches I used MTee for this purpose...

Martin

"Martin Zugec" <martin.zugec@xxxxxx> wrote in message
news:%2339fP$O3IHA.4164@xxxxxx
Quote:

> Hi everyone,
>
> writing my first script after 3 years I wanted to implement also
> different logs in it - event log support, overview log and debug log (this
> script will run as scheduled task).
>
> Event log and overview log are not problem. For debug log, I wanted to
> save full output to log file, so in case of any problems I could just
> check this "last session" log file.
>
> To my surprise I realized PowerShell behaves like "@Echo Off" in old
> batches - is there any way to switch it full output??
>
> Thanks,
> Martin
My System SpecsSystem Spec
Old 07-03-2008   #3 (permalink)
sapienscripter's Avatar
Scripting Guru


Join Date: Jun 2008
Vista Ultimate 32bit
Syracuse, NY
 
Rep Power: 8
sapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura about
  sapienscripter is offline

Re: "@Echo" behavior in PS scripts

So does Start-Transcript solve your problem or is there still an issue here?
My System SpecsSystem Spec
Old 07-03-2008   #4 (permalink)
Martin Zugec
Guest


 

Re: "@Echo" behavior in PS scripts

Well it doesn't work of course.

In batches:
- Default - output everything to console
- @Echo off - output only stdout\strerr

In PowerShell
- Default - output only stdout\strerr
- ???

Consider example with Hello world.

HelloWorld.cmd:
Echo Hello World

Output:
C:\>HelloWorld.cmd

C:\>Echo Hello world
Hello world

C:\>

HelloWorld.ps1
"Hello world"

Output:
PS C:\> .\HelloWorld.ps1
Hello world

In .cmd, I can change this behavior by using @Echo off\on. But how to change
it in powershell - I don't know

Martin

"sapienscripter" <guest@xxxxxx-email.com> wrote in message
news:a25cf76794efcfd28645d2dee62b7ee7@xxxxxx-gateway.com...
Quote:

>
> So does Start-Transcript solve your problem or is there still an issue
> here?
>
>
> --
> sapienscripter
>
> Coming Soon: 'Managing Active Directory with Windows PowerShell: TFM'
> (http://www.sapienpress.com/ad.asp)
>
> Windows PowerShell MVP
>
> 'My Blog' (http://blog.sapien.com/)
> 'FollowMe on Twitter' (http://www.twitter.com/JeffHicks)
My System SpecsSystem Spec
Old 07-03-2008   #5 (permalink)
sapienscripter's Avatar
Scripting Guru


Join Date: Jun 2008
Vista Ultimate 32bit
Syracuse, NY
 
Rep Power: 8
sapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura about
  sapienscripter is offline

Re: "@Echo" behavior in PS scripts

The first change is to start thinking of PowerShell as object oriented. While there is a console, it does not behave (obviously) like the CMD shell. When you run a PowerShell command, objects are sent through the pipeline. At the end of pipeline are default cmdlets that take the remaining objects in the pipeline and present a text display.

I can't think of a way to mimic the echo off/echo on technique in PowerShell. There are cmdlets you can use to save output to a file like Out-File. You might also look at Tee-Object which saves output to a file and displays it to the console. However, none of these will also capture the actual command. For that you would need to use Start-Transcript. If you wanted a good log when running a script or function, I would add this cmdlet at the beginning to start logging and then turn it off at the end with Stop-Transcript.
My System SpecsSystem Spec
Old 07-03-2008   #6 (permalink)
Brandon [MVP]
Guest


 

Re: "@Echo" behavior in PS scripts

Try this function and see if you like it.

function `@echo
([switch]$off){if($off){stop-transcript}else{start-transcript}}

# helloworld.ps1
`@echo
write-Host "Hello"
write-Host "World"
`@echo -off

This is not exactly the same, but should give you what you want.

"Martin Zugec" <martin.zugec@xxxxxx> wrote in message
news:uPYdUYQ3IHA.3508@xxxxxx
Quote:

> Well it doesn't work of course.
>
> In batches:
> - Default - output everything to console
> - @Echo off - output only stdout\strerr
>
> In PowerShell
> - Default - output only stdout\strerr
> - ???
>
> Consider example with Hello world.
>
> HelloWorld.cmd:
> Echo Hello World
>
> Output:
> C:\>HelloWorld.cmd
>
> C:\>Echo Hello world
> Hello world
>
> C:\>
>
> HelloWorld.ps1
> "Hello world"
>
> Output:
> PS C:\> .\HelloWorld.ps1
> Hello world
>
> In .cmd, I can change this behavior by using @Echo off\on. But how to
> change it in powershell - I don't know
>
> Martin
>
> "sapienscripter" <guest@xxxxxx-email.com> wrote in message
> news:a25cf76794efcfd28645d2dee62b7ee7@xxxxxx-gateway.com...
Quote:

>>
>> So does Start-Transcript solve your problem or is there still an issue
>> here?
>>
>>
>> --
>> sapienscripter
>>
>> Coming Soon: 'Managing Active Directory with Windows PowerShell: TFM'
>> (http://www.sapienpress.com/ad.asp)
>>
>> Windows PowerShell MVP
>>
>> 'My Blog' (http://blog.sapien.com/)
>> 'FollowMe on Twitter' (http://www.twitter.com/JeffHicks)
>
My System SpecsSystem Spec
Old 07-03-2008   #7 (permalink)
Martin Zugec
Guest


 

Re: "@Echo" behavior in PS scripts

Hi Brandon,

first try that Hello world example Start-Transcript works fine - problem
I have is that PowerShell acts differently when it is running in interactive
session (do something, prompt, read prompt, do something, prompt, read
prompt) and something completely different when running from .ps1 file.

So transcript will only save stdout\strerr (which makes sense). I know it
sounds really really strange, but old cmd.exe was maybe more flexible here


Martin

"Brandon [MVP]" <tshell.mask@xxxxxx> wrote in message
news:7F072624-8B9C-4E65-AB5B-BDF07368125B@xxxxxx
Quote:

> Try this function and see if you like it.
>
> function `@echo
> ([switch]$off){if($off){stop-transcript}else{start-transcript}}
>
> # helloworld.ps1
> `@echo
> write-Host "Hello"
> write-Host "World"
> `@echo -off
>
> This is not exactly the same, but should give you what you want.
>
> "Martin Zugec" <martin.zugec@xxxxxx> wrote in message
> news:uPYdUYQ3IHA.3508@xxxxxx
Quote:

>> Well it doesn't work of course.
>>
>> In batches:
>> - Default - output everything to console
>> - @Echo off - output only stdout\strerr
>>
>> In PowerShell
>> - Default - output only stdout\strerr
>> - ???
>>
>> Consider example with Hello world.
>>
>> HelloWorld.cmd:
>> Echo Hello World
>>
>> Output:
>> C:\>HelloWorld.cmd
>>
>> C:\>Echo Hello world
>> Hello world
>>
>> C:\>
>>
>> HelloWorld.ps1
>> "Hello world"
>>
>> Output:
>> PS C:\> .\HelloWorld.ps1
>> Hello world
>>
>> In .cmd, I can change this behavior by using @Echo off\on. But how to
>> change it in powershell - I don't know
>>
>> Martin
>>
>> "sapienscripter" <guest@xxxxxx-email.com> wrote in message
>> news:a25cf76794efcfd28645d2dee62b7ee7@xxxxxx-gateway.com...
Quote:

>>>
>>> So does Start-Transcript solve your problem or is there still an issue
>>> here?
>>>
>>>
>>> --
>>> sapienscripter
>>>
>>> Coming Soon: 'Managing Active Directory with Windows PowerShell: TFM'
>>> (http://www.sapienpress.com/ad.asp)
>>>
>>> Windows PowerShell MVP
>>>
>>> 'My Blog' (http://blog.sapien.com/)
>>> 'FollowMe on Twitter' (http://www.twitter.com/JeffHicks)
>>
>
My System SpecsSystem Spec
Old 07-03-2008   #8 (permalink)
Martin Zugec
Guest


 

Re: "@Echo" behavior in PS scripts

Heya,

same reply as for Brandon - problem is not how to do it, its pretty fine
(either Start-Transcript or Tee-Object), problem is that when you run .ps1
script, there is (as far as I know) no way how to difine verbosity of that
script (stdin\strout or full). I am afraid this have nothing to do with
object-orientation of PowerShell.

Martin

"sapienscripter" <guest@xxxxxx-email.com> wrote in message
news:55c88dba1fc41dfc1abe7aaf3e6da755@xxxxxx-gateway.com...
Quote:

>
> The first change is to start thinking of PowerShell as object oriented.
> While there is a console, it does not behave (obviously) like the CMD
> shell. When you run a PowerShell command, objects are sent through the
> pipeline. At the end of pipeline are default cmdlets that take the
> remaining objects in the pipeline and present a text display.
>
> I can't think of a way to mimic the echo off/echo on technique in
> PowerShell. There are cmdlets you can use to save output to a file like
> Out-File. You might also look at Tee-Object which saves output to a file
> and displays it to the console. However, none of these will also
> capture the actual command. For that you would need to use
> Start-Transcript. If you wanted a good log when running a script or
> function, I would add this cmdlet at the beginning to start logging and
> then turn it off at the end with Stop-Transcript.
>
>
> --
> sapienscripter
>
> Coming Soon: 'Managing Active Directory with Windows PowerShell: TFM'
> (http://www.sapienpress.com/ad.asp)
>
> Windows PowerShell MVP
>
> 'My Blog' (http://blog.sapien.com/)
> 'FollowMe on Twitter' (http://www.twitter.com/JeffHicks)
My System SpecsSystem Spec
Old 07-03-2008   #9 (permalink)
sapienscripter's Avatar
Scripting Guru


Join Date: Jun 2008
Vista Ultimate 32bit
Syracuse, NY
 
Rep Power: 8
sapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura about
  sapienscripter is offline

Re: "@Echo" behavior in PS scripts

You are trying to impose essentially text based techniques on an object oriented shell and it won't work. At the interactive level, you'll need to use Start-Transcript. One thing I just discovered is that Echo is an alias for Write-Output.
My System SpecsSystem Spec
Old 07-03-2008   #10 (permalink)
sapienscripter's Avatar
Scripting Guru


Join Date: Jun 2008
Vista Ultimate 32bit
Syracuse, NY
 
Rep Power: 8
sapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura aboutsapienscripter has a spectacular aura about
  sapienscripter is offline

Re: "@Echo" behavior in PS scripts

The more I read this thread the more I'm not sure what you are really after. It seems that when using a script in PowerShell the transcript technique will meet your needs. Is that correct?

When it comes to the interactive shell I think you still have an issue. Can you give a more practical example of something you would do in the CMD shell that you are trying to recreate in PowerShell? Something other than "hello world".
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unwanted Multiple contacts in "To","CC","BCC" of email send catago xsailer Vista mail 1 07-26-2008 08:34 AM
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Platebanger Vista General 6 02-05-2008 08:54 AM
Incorrect behavior of GPO "Access this computer from the network" HAL Vista General 1 06-04-2007 03:21 AM
WM5 Sync with Vista "Windows Calender", "Contacts", and "Mail" Tony Vista General 1 02-16-2007 06:20 PM
"Close Lid behavior" broken Jon Davis Vista General 29 01-02-2007 02:21 PM


Vistax64.com 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 2005-2008

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 47 48 49 50 51