第一次运行时PS脚本错误:类型为“0”的对象;。PowerShell.Commands.Internal.Format.FormatStartData“文件;无效或顺序不正确
我有一个在2012r2中正常工作的函数,当我在2008R2中运行它时,它抛出以下错误。令人惊讶的是,如果我第二次执行它,它会毫无问题地工作第一次运行时PS脚本错误:类型为“0”的对象;。PowerShell.Commands.Internal.Format.FormatStartData“文件;无效或顺序不正确,powershell,Powershell,我有一个在2012r2中正常工作的函数,当我在2008R2中运行它时,它抛出以下错误。令人惊讶的是,如果我第二次执行它,它会毫无问题地工作 # Function Reg-Stamp { Param( [Parameter(Mandatory=$True)] [string]$Phase ) $msg = "`nEntering: $((Get-Variable MyInvocation -Scope 0).Value.MyCommand.Name)" ; Write-Host -for
# 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
这解决了错误
但是,我仍然不明白为什么只有在第一次运行时才会发生错误。
我之前也提到过这个问题,但它非常一致。
你知道为什么吗?你知道错误的行号吗?没有,但事实证明问题根本不在上面的脚本中。调用方脚本似乎有一行涉及格式表的内容,该行与此脚本无关,这是导致问题的原因$SupportFilesInfo=导入csv$SupportFilesCSV |选择对象$SupportFilesInfo | ft$SupportFilesInfo | Out File-append$logs很有意义,这就是为什么我要这行|,因为没有什么不寻常的。谢谢,但是你知道为什么第一次会出现吗。每当我看到这种类型的错误时,它总是不断地发生。不是没有看到你的代码