20

I am attempting to run the following code to retrieve a list of local users on a machine.

gwmi win32_useraccount -Computername $env:computername -Filter "Domain='$env:computername'" |
  Format-Table Name,Description

I get this error when running inside a PS1 file:

 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 "f ormat-table" command which is conflicting with the
 default formatting.
     + CategoryInfo          : InvalidData: (:) [out-lineoutput],
 InvalidOperationException
     + FullyQualifiedErrorId :
 ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

I understand this issue arises because of the way the pipelines are parsed but I can't figure out how to get around it.

2 Answers 2

23

The Format-* cmdlets do not do final output, but transform their input into a sequence of formatting objects. These formatting objects are converted to the actual output by one of the Out- cmdlets, probably Out-Default.

If a script has multiple, different sets of formatting objects that final output of the merged objects from all the expressions in the script Out-Default cannot resolve the inconsistencies.

Fix: add a Out-String to the end of each output generating pipeline to perform the formatting one expression at a time:

gwmi win32_useraccount -Computername $env:computername -Filter "Domain='$env:computername'" |
  Format-Table Name,Description | Out-String
Sign up to request clarification or add additional context in comments.

2 Comments

I do not reproduce with this command on my seven, But it appends to me with other WMI class.
@manojlds The problem comes when running multiple output producing statements together in a single execution. You can get the same on the command line by having two commands together on a single command line with the ; statement separator. In some cases it works, in others it doesn't. But forcing output to be strings which are displayed directly has always worked for me.
1

you can also try :

gwmi win32_useraccount -Computername $env:computername -Filter "Domain='$env:computername'"  | Select-Object Name,Description  | Format-Table Name,Description

In fact you convert to an intermediate PSCustomObject and you still have an object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.