Archive site from 2010 and earlier

Powershell

I found a really weird bug/feature in powershell today.

I couldn't figure out why I was getting errors like:

Object of type
 "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not legal
or not in the correct sequence. This is likely caused by a user-specified
"format-list" command which is conflicting with the default formatting. --->
System.InvalidOperationException: Operation is not valid due to the current
state of the object.

   at
System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecor
d errorRecord)

   --- End of inner exception stack trace ---

   at
System.Management.Automation.Internal.PipelineProcessor.DoStepItems(Object
input, Hashtable errorResults, Boolean enumerate)

   at System.Management.Automation.Internal.PipelineProcessor.Step(Object
input)

   at
Microsoft.PowerShell.Commands.Internal.Format.CommandWrapper.Process(Object o)

   at
Microsoft.PowerShell.Commands.Internal.Format.SubPipelineManager.Process(PSObje
ct so)

   at
Microsoft.PowerShell.Commands.Internal.Format.OutputManagerInner.ProcessRecord(
)

   at
Microsoft.PowerShell.Commands.Internal.Format.FrontEndCommandBase.ProcessRecord
()

   at System.Management.Automation.Cmdlet.DoProcessRecord()

   at System.Management.Automation.CommandProcessor.ProcessRecord()

out-lineoutput : Object of type "Microsoft.PowerShell.Commands.Internal.Format.
FormatStartData" is not legal or not in the correct sequence. This is likely ca
used by a user-specified "format-list" command which is conflicting with the de
fault formatting.


After some googling, I found an answer written by Don Jones in a forum.

Aparrently, the semicolon does not terminate a pipeline, so any code that appears after the semi colon is treated as part of the pipeline, which ultimately gets piped implicitly to Out-Default, which sometimes doesn't know how to handle the output, causing this error.