PowerShell formatting issue in Function or Workflow


Hi All,

If you see below error . you might be calling the format function in function or some workflow.

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-list" command which is

conflicting with the default formatting

Wrong work flow code:

workflow parallelEventCheck {

param(

[String[]]$ComputerName,

[string]$EventMessage,

[string[]]$ApplicationList

)

foreach –parallel ($Appname in $ApplicationList)

{

inlinescript{

Get-EventLog -LogName $Using:Appname -Newest 10 -Message "*$Using:EventMessage*" |format-table # don’t use like this

}

}

}#parallelEventCheck

parallelEventCheck -PSComputerName `

Server1,Server2

-EventMessage Error `

-ApplicationList ‘Application’,’System’ |out-gridview

Correct work flow code:

workflow parallelEventCheck {

param(

[String[]]$ComputerName,

[string]$EventMessage,

[string[]]$ApplicationList

)

foreach –parallel ($Appname in $ApplicationList)

{

inlinescript{

Get-EventLog -LogName $Using:Appname -Newest 10 -Message "*$Using:EventMessage*"

}

}

}#parallelEventCheck

parallelEventCheck -PSComputerName `

Server1,Server2

-EventMessage Error `

-ApplicationList ‘Application’,’System’ |format-table # don’t use the format command in function . you can pipe the function output to format command.

Regards,

Chaitanya

Leave a comment

Design a site like this with WordPress.com
Get started