首次运行时出现PS脚本错误:类型为“.PowerShell.Commands.Internal.Format.FormatStartData”的对象无效或者顺序不正确

时间:2014-06-05 16:00:53

标签: powershell

我有以下功能在2012r2中正常工作,当我在2008R2中运行它时会抛出以下错误。令人惊讶的是,如果我第二次执行它,它的工作没有任何问题!!

# Function Reg-Stamp {
Param(
[Parameter(Mandatory=$True)]
[string]$Phase
)

$msg = "`nEntering: $((Get-Variable MyInvocation -Scope 0).Value.MyCommand.Name)" ;     Write-Host -fore Gray $msg ; $msg | out-file -Append $log


$RegStampInfo = Build-Variable $RegStampCSV


$Version = ($ScriptVersionInfo | Where-Object {$_.Parameter -eq "Version" -and $_.Phase  -eq $Phase }).Value
$DisplayName = ($ScriptVersionInfo | Where-Object {$_.Parameter -eq "DisplayName" -and     $_.Phase -eq $Phase }).Value
$BuildDate = ($ScriptVersionInfo | Where-Object {$_.Parameter -eq "BuildDate" -and $_.Phase -eq $Phase }).Value
$RunDate = Get-Date
$Success = $(-not($CriticalError))

$msg = "`nUpdating registry with build information"; Write-Host -fore Gray $msg; $msg | out-file $log -Append;

$RegStampInfo | Where-Object {($_.Phase.ToLower()) -eq ($Phase.ToLower())} | foreach-Object {

$ValueData = $(get-variable -Name $($_.StampData) -ValueOnly -ErrorAction SilentlyContinue) 
$msg = "Adding Key: $($_.StampKey) '$($_.StampValue)' '$ValueData'"; Write-Host -fore Green "$msg"; $msg | out-file $log -Append;

New-Item -Path $($_.StampKey) -ErrorAction SilentlyContinue
Set-ItemProperty -Path $_.StampKey -name $_.StampValue -Value $ValueData

}

$msg = "`nExiting: $((Get-Variable MyInvocation -Scope 0).Value.MyCommand.Name)"; Write-Host -fore DarkGreen  $msg ; $msg | out-file -Append $log

    #}

我收到以下错误:

out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.For
mat.FormatStartData" is not valid or not in the correct sequence. This is likel
y caused by a user-specified "format-table" command which is conflicting with t
he default formatting.
    + CategoryInfo          : InvalidData: (:) [out-lineoutput], InvalidOperat
   ionException
    + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.P
   owerShell.Commands.OutLineOutputCommand

我在使用format-table时在powershell中看到了类似的错误,但是我没有直接在这里使用fr。 不确定有什么问题!

编辑: 不,但事实证明问题根本不在上述脚本中。 看来调用者脚本有一行涉及格式表,这与该脚本无关,导致问题。

$SupportFilesInfo = Import-csv $SupportFilesCSV | select-object
$SupportFilesInfo | ft ; $SupportFilesInfo | Out-File -append $log

我把它改为:

$SupportFilesInfo | ft | out-default; $SupportFilesInfo | Out-File -append $log

解决了错误!!

但是,我仍然不知道为什么错误仅在第一次运行期间发生。 我之前也遇到过这个问题,但它非常一致。 知道为什么吗?

0 个答案:

没有答案