1

I am running following script in powershell script and getting error.

$queues = Get-WmiObject Win32_PerfFormattedData_msmq_MSMQQueue

$list = $queues | ft -property Name,MessagesInQueue

for ( $i = 0; $i -lt 6; $i++ ) {

if ($i -gt 2) {

$list[$i] 

}

}

Error: out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-*" command which is conflicting with the default formatting. + CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand

1 Answer 1

2

It looks like you are simply trying to skip the headers for your data when displayed with Format-Table (or FT for short as you used). To do that just use the -HideTableHeaders switch on your FT command, and don't capture it in a variable.

$queues = Get-WmiObject Win32_PerfFormattedData_msmq_MSMQQueue
$queues | ft -property Name,MessagesInQueue -HideTableHeaders

For that matter, you should only use Format-Table or any of the Format- commands to display text, not to store in a variable. If you only want the first 4 entries you would pipe to a Select command before the FT like:

$queues = Get-WmiObject Win32_PerfFormattedData_msmq_MSMQQueue
$queues | Select -First 4 | ft -property Name,MessagesInQueue -HideTableHeaders
Sign up to request clarification or add additional context in comments.

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.