Why is Out-Default required here?

H

Hans Dingemans

gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} -first 1
gps | select -first 1 | ft name, vm,
@{label='MB';e={[int]($_.vm/1mb)}} -autosize

The above two statements work just fine when entered via keyboard. If you
put them in a .ps1 script file I get an error and the second pipe is not
executed.

PS> .\test.ps1

Name VM
MB
---- --
--
AcroRd32 165748736
158
out-lineoutput : The object of type
"Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid
or not in the correct sequence. This is likely caused by a user-specified
"format-table" command which is conflicting with the default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput],
InvalidOperation Exception
+ FullyQualifiedErrorId :
ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
PS>

When I explicitly pipe the first statement to Out-Default, it works just
fine from the script too.

gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} -first 1 |
Out-Default # <===
gps | select -first 1 | ft name, vm,
@{label='MB';e={[int]($_.vm/1mb)}} -autosize

How come?

Thanx for any reaction,

Hans Dingemans
 

My Computer

W

Wolfgang Kais

Hello Hans.

Hans Dingemans wrote:

> gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} `
> -first 1
> gps | select -first 1 | ft name, vm,
> @{label='MB';e={[int]($_.vm/1mb)}} -autosize
>
> The above two statements work just fine when entered via keyboard.
> If you put them in a .ps1 script file I get an error and the second
> pipe is not executed.
The first pipeline returns a Selected.System.Diagnostics.Process object,
the second one returns special formatting object. All of these objects
are passed down the script pipeline which only consists of the call of
the script, so all returned objects have to be displayed somehow. It
seems that the formatting objects can't be "displayed" together with
other objects.

> When I explicitly pipe the first statement to Out-Default, it works
> just fine from the script too.
Out-Default performs default formatting and sends the objects to the
host (Out-Host), so the selected process will not be returned in the
script pipeline, so there is no conflict with the formatting objects
when the objects returned by the script are to be displayed.

--
Kind regards,
Wolfgang
 

My Computer

L

Larry__Weiss

It has to do with putting dissimilar objects in the pipeline
and then having a formatter try to deal with them.

See the two comments by Don Jones at
http://www.minasi.com/forum/topic.asp?TOPIC_ID=20456#103477

These incident reports have been opened on this topic

https://connect.microsoft.com/PowerShell/feedback/details/333752/same-command-with-different-output-fails-if-run-in-sequence

https://connect.microsoft.com/PowerShell/feedback/details/152205/bug-with-default-formatter

https://connect.microsoft.com/PowerShell/feedback/details/549043/apply-formatting-to-multiple-dissimilar-object-types-emitted-from-the-pipeline#details

- Larry

On 5/20/2010 6:21 AM, Hans Dingemans wrote:

> gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} -first 1
> gps | select -first 1 | ft name, vm, @{label='MB';e={[int]($_.vm/1mb)}}
> -autosize
>
> The above two statements work just fine when entered via keyboard. If
> you put them in a .ps1 script file I get an error and the second pipe is
> not executed.
>
> PS> .\test.ps1
>
> Name VM MB
> ---- -- --
> AcroRd32 165748736 158
> out-lineoutput : The object of type
> "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not
> valid or not in the correct sequence. This is likely caused by a
> user-specified "format-table" command which is conflicting with the
> default formatting.
> + CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperation
> Exception
> + FullyQualifiedErrorId :
> ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
>
> PS>
>
> When I explicitly pipe the first statement to Out-Default, it works just
> fine from the script too.
>
> gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} -first
> 1 | Out-Default # <===
> gps | select -first 1 | ft name, vm, @{label='MB';e={[int]($_.vm/1mb)}}
> -autosize
>
> How come?
>
> Thanx for any reaction,
>
> Hans Dingemans
 

My Computer

H

Hans Dingemans

Thanx to both Wolfgang and Larry!

Useful info :-)

"Hans Dingemans" <[email protected]> schreef in bericht
news:eoP##5A#[email protected]

> gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} -first 1
> gps | select -first 1 | ft name, vm,
> @{label='MB';e={[int]($_.vm/1mb)}} -autosize
>
> The above two statements work just fine when entered via keyboard. If you
> put them in a .ps1 script file I get an error and the second pipe is not
> executed.
>
> PS> .\test.ps1
>
> Name VM MB
> ---- --
> --
> AcroRd32 165748736 158
> out-lineoutput : The object of type
> "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not
> valid or not in the correct sequence. This is likely caused by a
> user-specified "format-table" command which is conflicting with the
> default formatting.
> + CategoryInfo : InvalidData: (:) [out-lineoutput],
> InvalidOperation Exception
> + FullyQualifiedErrorId :
> ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
> PS>
>
> When I explicitly pipe the first statement to Out-Default, it works just
> fine from the script too.
>
> gps | select name, vm, @{name='MB';expression={[int]($_.vm/1mb)}} -first 1
> | Out-Default # <===
> gps | select -first 1 | ft name, vm,
> @{label='MB';e={[int]($_.vm/1mb)}} -autosize
>
> How come?
>
> Thanx for any reaction,
>
> Hans Dingemans
 

My Computer

Top