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 - output format with multiple commands

Reply
 
Old 02-12-2007   #1 (permalink)
William Stacey [C# MVP]


 
 

output format with multiple commands

Why does second command not get formatted as normal? tia

PS C:\TEMP> ps winss; get-date

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
643 17 16304 10212 110 72.63 2100 winss

DisplayHint : DateTime
DateTime : Monday, February 12, 2007 1:14:21 AM
Date : 2/12/2007 12:00:00 AM
Day : 12
DayOfWeek : Monday
DayOfYear : 43
Hour : 1
Kind : Local
Millisecond : 937
Minute : 14
Month : 2
Second : 21
Ticks : 633068396619375000
TimeOfDay : 01:14:21.9375000
Year : 2007

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject




My System SpecsSystem Spec
Old 02-12-2007   #2 (permalink)
RichS


 
 

RE: output format with multiple commands

Interestingly if you reverse the order of commands you get this

PS> get-date; get-process

12 February 2007 07:51:42

Id : 2544
Handles : 104
CPU : 0.0625
Name : alg

etc

Looks like the second command will ignore any formatting and defalut to
format-list

If you put the commands on two consecutive lines in a script it doesn't
appear to matter which order you put the commands you get the same result as
your original post

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"William Stacey [C# MVP]" wrote:

> Why does second command not get formatted as normal? tia
>
> PS C:\TEMP> ps winss; get-date
>
> Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
> ------- ------ ----- ----- ----- ------ -- -----------
> 643 17 16304 10212 110 72.63 2100 winss
>
> DisplayHint : DateTime
> DateTime : Monday, February 12, 2007 1:14:21 AM
> Date : 2/12/2007 12:00:00 AM
> Day : 12
> DayOfWeek : Monday
> DayOfYear : 43
> Hour : 1
> Kind : Local
> Millisecond : 937
> Minute : 14
> Month : 2
> Second : 21
> Ticks : 633068396619375000
> TimeOfDay : 01:14:21.9375000
> Year : 2007
>
> --
> William Stacey [C# MVP]
> PCR concurrency library: www.codeplex.com/pcr
> PSH Scripts Project www.codeplex.com/psobject
>
>
>
>

My System SpecsSystem Spec
Old 02-12-2007   #3 (permalink)
/\/\o\/\/ [MVP]


 
 

RE: output format with multiple commands

This is a know problem

if you have different object's on one pipeline you have to explicetly format
them .

Greetings /\/\o\/\/

"RichS" wrote:

> Interestingly if you reverse the order of commands you get this
>
> PS> get-date; get-process
>
> 12 February 2007 07:51:42
>
> Id : 2544
> Handles : 104
> CPU : 0.0625
> Name : alg
>
> etc
>
> Looks like the second command will ignore any formatting and defalut to
> format-list
>
> If you put the commands on two consecutive lines in a script it doesn't
> appear to matter which order you put the commands you get the same result as
> your original post
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "William Stacey [C# MVP]" wrote:
>
> > Why does second command not get formatted as normal? tia
> >
> > PS C:\TEMP> ps winss; get-date
> >
> > Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
> > ------- ------ ----- ----- ----- ------ -- -----------
> > 643 17 16304 10212 110 72.63 2100 winss
> >
> > DisplayHint : DateTime
> > DateTime : Monday, February 12, 2007 1:14:21 AM
> > Date : 2/12/2007 12:00:00 AM
> > Day : 12
> > DayOfWeek : Monday
> > DayOfYear : 43
> > Hour : 1
> > Kind : Local
> > Millisecond : 937
> > Minute : 14
> > Month : 2
> > Second : 21
> > Ticks : 633068396619375000
> > TimeOfDay : 01:14:21.9375000
> > Year : 2007
> >
> > --
> > William Stacey [C# MVP]
> > PCR concurrency library: www.codeplex.com/pcr
> > PSH Scripts Project www.codeplex.com/psobject
> >
> >
> >
> >

My System SpecsSystem Spec
Old 02-12-2007   #4 (permalink)
William Stacey [C# MVP]


 
 

Re: output format with multiple commands

But I get the same results as different lines in a script. Is that the same
issue? Wouldn't each line be a new pipeline with " | out-default" appended?
tia

PS C:\TEMP> cat myjob.ps1
dir c:\temp\*.txt
get-date

PS C:\TEMP> .\myjob.ps1

Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/7/2007 3:45 AM 12 job1.txt
-a--- 2/6/2007 12:11 AM 0 jobs.txt
-a--- 2/8/2007 12:11 PM 4672 log.txt
-a--- 2/7/2007 2:59 AM 54 out.txt
-a--- 2/11/2007 4:47 PM 1458 tmp.txt

DisplayHint : DateTime
DateTime : Monday, February 12, 2007 10:07:47 AM
Date : 2/12/2007 12:00:00 AM
Day : 12
DayOfWeek : Monday
DayOfYear : 43
Hour : 10
Kind : Local
Millisecond : 734
Minute : 7
Month : 2
Second : 47
Ticks : 633068716677343750
TimeOfDay : 10:07:47.7343750
Year : 2007

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject


"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:20571317-01BB-4FB2-948C-7A26E08EE882@microsoft.com...
| This is a know problem
|
| if you have different object's on one pipeline you have to explicetly
format
| them .
|
| Greetings /\/\o\/\/
|
| "RichS" wrote:
|
| > Interestingly if you reverse the order of commands you get this
| >
| > PS> get-date; get-process
| >
| > 12 February 2007 07:51:42
| >
| > Id : 2544
| > Handles : 104
| > CPU : 0.0625
| > Name : alg
| >
| > etc
| >
| > Looks like the second command will ignore any formatting and defalut to
| > format-list
| >
| > If you put the commands on two consecutive lines in a script it doesn't
| > appear to matter which order you put the commands you get the same
result as
| > your original post
| >
| > --
| > Richard Siddaway
| > Please note that all scripts are supplied "as is" and with no warranty
| > Blog: http://richardsiddaway.spaces.live.com/
| > PowerShell User Group: http://www.get-psuguk.org.uk
| >
| >
| > "William Stacey [C# MVP]" wrote:
| >
| > > Why does second command not get formatted as normal? tia
| > >
| > > PS C:\TEMP> ps winss; get-date
| > >
| > > Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
| > > ------- ------ ----- ----- ----- ------ -- -----------
| > > 643 17 16304 10212 110 72.63 2100 winss
| > >
| > > DisplayHint : DateTime
| > > DateTime : Monday, February 12, 2007 1:14:21 AM
| > > Date : 2/12/2007 12:00:00 AM
| > > Day : 12
| > > DayOfWeek : Monday
| > > DayOfYear : 43
| > > Hour : 1
| > > Kind : Local
| > > Millisecond : 937
| > > Minute : 14
| > > Month : 2
| > > Second : 21
| > > Ticks : 633068396619375000
| > > TimeOfDay : 01:14:21.9375000
| > > Year : 2007
| > >
| > > --
| > > William Stacey [C# MVP]
| > > PCR concurrency library: www.codeplex.com/pcr
| > > PSH Scripts Project www.codeplex.com/psobject
| > >
| > >
| > >
| > >


My System SpecsSystem Spec
Old 02-12-2007   #5 (permalink)
/\/\o\/\/ [MVP]


 
 

Re: output format with multiple commands

Yes,same issue (whole script in same pipeline so also different object will
be in one pipeline )

There were some threads about this before

As this issue / concept is hard to explain (and happens often) maybe it's
an idea for a blogentry in the Teamblog (Bruce ?)

Greetings /\/\o\/\/

"William Stacey [C# MVP]" wrote:

> But I get the same results as different lines in a script. Is that the same
> issue? Wouldn't each line be a new pipeline with " | out-default" appended?
> tia
>
> PS C:\TEMP> cat myjob.ps1
> dir c:\temp\*.txt
> get-date
>
> PS C:\TEMP> .\myjob.ps1
>
> Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> -a--- 2/7/2007 3:45 AM 12 job1.txt
> -a--- 2/6/2007 12:11 AM 0 jobs.txt
> -a--- 2/8/2007 12:11 PM 4672 log.txt
> -a--- 2/7/2007 2:59 AM 54 out.txt
> -a--- 2/11/2007 4:47 PM 1458 tmp.txt
>
> DisplayHint : DateTime
> DateTime : Monday, February 12, 2007 10:07:47 AM
> Date : 2/12/2007 12:00:00 AM
> Day : 12
> DayOfWeek : Monday
> DayOfYear : 43
> Hour : 10
> Kind : Local
> Millisecond : 734
> Minute : 7
> Month : 2
> Second : 47
> Ticks : 633068716677343750
> TimeOfDay : 10:07:47.7343750
> Year : 2007
>
> --
> William Stacey [C# MVP]
> PCR concurrency library: www.codeplex.com/pcr
> PSH Scripts Project www.codeplex.com/psobject
>
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:20571317-01BB-4FB2-948C-7A26E08EE882@microsoft.com...
> | This is a know problem
> |
> | if you have different object's on one pipeline you have to explicetly
> format
> | them .
> |
> | Greetings /\/\o\/\/
> |
> | "RichS" wrote:
> |
> | > Interestingly if you reverse the order of commands you get this
> | >
> | > PS> get-date; get-process
> | >
> | > 12 February 2007 07:51:42
> | >
> | > Id : 2544
> | > Handles : 104
> | > CPU : 0.0625
> | > Name : alg
> | >
> | > etc
> | >
> | > Looks like the second command will ignore any formatting and defalut to
> | > format-list
> | >
> | > If you put the commands on two consecutive lines in a script it doesn't
> | > appear to matter which order you put the commands you get the same
> result as
> | > your original post
> | >
> | > --
> | > Richard Siddaway
> | > Please note that all scripts are supplied "as is" and with no warranty
> | > Blog: http://richardsiddaway.spaces.live.com/
> | > PowerShell User Group: http://www.get-psuguk.org.uk
> | >
> | >
> | > "William Stacey [C# MVP]" wrote:
> | >
> | > > Why does second command not get formatted as normal? tia
> | > >
> | > > PS C:\TEMP> ps winss; get-date
> | > >
> | > > Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
> | > > ------- ------ ----- ----- ----- ------ -- -----------
> | > > 643 17 16304 10212 110 72.63 2100 winss
> | > >
> | > > DisplayHint : DateTime
> | > > DateTime : Monday, February 12, 2007 1:14:21 AM
> | > > Date : 2/12/2007 12:00:00 AM
> | > > Day : 12
> | > > DayOfWeek : Monday
> | > > DayOfYear : 43
> | > > Hour : 1
> | > > Kind : Local
> | > > Millisecond : 937
> | > > Minute : 14
> | > > Month : 2
> | > > Second : 21
> | > > Ticks : 633068396619375000
> | > > TimeOfDay : 01:14:21.9375000
> | > > Year : 2007
> | > >
> | > > --
> | > > William Stacey [C# MVP]
> | > > PCR concurrency library: www.codeplex.com/pcr
> | > > PSH Scripts Project www.codeplex.com/psobject
> | > >
> | > >
> | > >
> | > >
>
>
>

My System SpecsSystem Spec
Old 02-12-2007   #6 (permalink)
John Vottero


 
 

Re: output format with multiple commands

"William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
news:OWN$AgrTHHA.5060@TK2MSFTNGP02.phx.gbl...
> But I get the same results as different lines in a script. Is that the
> same
> issue? Wouldn't each line be a new pipeline with " | out-default"
> appended?
> tia


That confused me for a while too. If you want " | out-default" after each
line, you have to put it there. Otherwise all the objects returned by the
script get pushed out the pipeline to whatever is out there, if it's going
to out-default (as in your examples), out-default looks at the first object
to figure out how to format. If the objects change, out-default doesn't
look for formatting again, it just drops to default formatting. I'm not
sure if that's considered a bug or not.




My System SpecsSystem Spec
Old 02-12-2007   #7 (permalink)
William Stacey [C# MVP]


 
 

Re: output format with multiple commands

So a script is converted to a script block before exec?

Script.ps1
---------------
line1
line2

Converts to =>

&{
//line1
//line2
} | out-default

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject


"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:3506DD4E-E682-4F78-9960-6D444F829346@microsoft.com...
| Yes,same issue (whole script in same pipeline so also different object
will
| be in one pipeline )
|
| There were some threads about this before
|
| As this issue / concept is hard to explain (and happens often) maybe it's
| an idea for a blogentry in the Teamblog (Bruce ?)
|
| Greetings /\/\o\/\/
|
| "William Stacey [C# MVP]" wrote:
|
| > But I get the same results as different lines in a script. Is that the
same
| > issue? Wouldn't each line be a new pipeline with " | out-default"
appended?
| > tia
| >
| > PS C:\TEMP> cat myjob.ps1
| > dir c:\temp\*.txt
| > get-date
| >
| > PS C:\TEMP> .\myjob.ps1
| >
| > Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp
| >
| >
| > Mode LastWriteTime Length Name
| > ---- ------------- ------ ----
| > -a--- 2/7/2007 3:45 AM 12 job1.txt
| > -a--- 2/6/2007 12:11 AM 0 jobs.txt
| > -a--- 2/8/2007 12:11 PM 4672 log.txt
| > -a--- 2/7/2007 2:59 AM 54 out.txt
| > -a--- 2/11/2007 4:47 PM 1458 tmp.txt
| >
| > DisplayHint : DateTime
| > DateTime : Monday, February 12, 2007 10:07:47 AM
| > Date : 2/12/2007 12:00:00 AM
| > Day : 12
| > DayOfWeek : Monday
| > DayOfYear : 43
| > Hour : 10
| > Kind : Local
| > Millisecond : 734
| > Minute : 7
| > Month : 2
| > Second : 47
| > Ticks : 633068716677343750
| > TimeOfDay : 10:07:47.7343750
| > Year : 2007
| >
| > --
| > William Stacey [C# MVP]
| > PCR concurrency library: www.codeplex.com/pcr
| > PSH Scripts Project www.codeplex.com/psobject
| >
| >
| > "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
| > news:20571317-01BB-4FB2-948C-7A26E08EE882@microsoft.com...
| > | This is a know problem
| > |
| > | if you have different object's on one pipeline you have to explicetly
| > format
| > | them .
| > |
| > | Greetings /\/\o\/\/
| > |
| > | "RichS" wrote:
| > |
| > | > Interestingly if you reverse the order of commands you get this
| > | >
| > | > PS> get-date; get-process
| > | >
| > | > 12 February 2007 07:51:42
| > | >
| > | > Id : 2544
| > | > Handles : 104
| > | > CPU : 0.0625
| > | > Name : alg
| > | >
| > | > etc
| > | >
| > | > Looks like the second command will ignore any formatting and defalut
to
| > | > format-list
| > | >
| > | > If you put the commands on two consecutive lines in a script it
doesn't
| > | > appear to matter which order you put the commands you get the same
| > result as
| > | > your original post
| > | >
| > | > --
| > | > Richard Siddaway
| > | > Please note that all scripts are supplied "as is" and with no
warranty
| > | > Blog: http://richardsiddaway.spaces.live.com/
| > | > PowerShell User Group: http://www.get-psuguk.org.uk
| > | >
| > | >
| > | > "William Stacey [C# MVP]" wrote:
| > | >
| > | > > Why does second command not get formatted as normal? tia
| > | > >
| > | > > PS C:\TEMP> ps winss; get-date
| > | > >
| > | > > Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id
ProcessName
| > | >
> ------- ------ ----- ----- ----- ------ -- -----------

| > | > > 643 17 16304 10212 110 72.63 2100 winss
| > | > >
| > | > > DisplayHint : DateTime
| > | > > DateTime : Monday, February 12, 2007 1:14:21 AM
| > | > > Date : 2/12/2007 12:00:00 AM
| > | > > Day : 12
| > | > > DayOfWeek : Monday
| > | > > DayOfYear : 43
| > | > > Hour : 1
| > | > > Kind : Local
| > | > > Millisecond : 937
| > | > > Minute : 14
| > | > > Month : 2
| > | > > Second : 21
| > | > > Ticks : 633068396619375000
| > | > > TimeOfDay : 01:14:21.9375000
| > | > > Year : 2007
| > | > >
| > | > > --
| > | > > William Stacey [C# MVP]
| > | > > PCR concurrency library: www.codeplex.com/pcr
| > | > > PSH Scripts Project www.codeplex.com/psobject
| > | > >
| > | > >
| > | > >
| > | > >
| >
| >
| >


My System SpecsSystem Spec
Old 02-13-2007   #8 (permalink)
John Vottero


 
 

Re: output format with multiple commands

"William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
news:%23tlyYzuTHHA.3500@TK2MSFTNGP05.phx.gbl...
> So a script is converted to a script block before exec?
>
> Script.ps1
> ---------------
> line1
> line2
>
> Converts to =>
>
> &{
> //line1
> //line2
> } | out-default
>


If it didn't work that way, you wouldn't be able to do:

..\Script.ps1 | sort



My System SpecsSystem Spec
Old 02-13-2007   #9 (permalink)
William Stacey [C# MVP]


 
 

Re: output format with multiple commands

| If it didn't work that way, you wouldn't be able to do:
|
| .\Script.ps1 | sort

Would that be converted to:?

&{
.\Script.ps1 | sort
} | out-default


My System SpecsSystem Spec
Old 02-13-2007   #10 (permalink)
John Vottero


 
 

Re: output format with multiple commands

"William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
news:OBmB364THHA.4872@TK2MSFTNGP03.phx.gbl...
>| If it didn't work that way, you wouldn't be able to do:
> |
> | .\Script.ps1 | sort
>
> Would that be converted to:?
>
> &{
> .\Script.ps1 | sort
> } | out-default
>


I'm not sure what you mean by "converted to". It actually depends on the
host that's executing the script but, I doubt that there's any text
manipulation going on. It's probably something like this (in C#):

Pipeline pipe = runspace.CreatePipeline();

pipe.Commands.AddScript(".\Script.ps1 | sort");
pipe.Commands.Add("out-default");
pipe.Invoke();


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Output changes depending upon order of commands and previous comma PowerShell
Multiple commands in batch file loop Vista General
Multiple commands in batch file loop PowerShell
Bug spreading pipeline commands across multiple lines in a script PowerShell
PS script prints output instead of executing commands 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