c# - 由于使用 sitecore 的对象的当前状态,该操作无效

标签 c# powershell recursion sitecore sitecore7

我在 sitecore powershell 上运行此代码,以便在路径中创建新的语言文件:

Get-ChildItem "master:\Print Studio\Print Studio Projects\Maax Product Catalogs\Prof CAN Catalog T2\Books\P_Book\Documents\Full Catalog FR\Pages\Prof-FSBathtubsSectionSnippet\"  -Recurse -Language "en"   | `
    Add-ItemLanguage -TargetLanguage "fr-CA" -IfExist Append | `
    Format-Table Name, Language, Version -auto

当使用-Recurse时我收到此错误

The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or does not appear in the correct order. The reason is probably a conflict between an order "format-list" specified by the user and default formatting.

Of type: System.Management.Automation.CmdletInvocationException
Stack trace:
   to System.Management.Automation.Internal.PipelineProcessor.DoStepItems (Object input, errorResults Hashtable, Boolean enumerate)
   to Microsoft.PowerShell.Commands.Internal.Format.CommandWrapper.Process (Object o)
   to Microsoft.PowerShell.Commands.Internal.Format.SubPipelineManager.Process (PSObject so)
   to Microsoft.PowerShell.Commands.Internal.Format.OutputManagerInner.ProcessRecord ()
   to Microsoft.PowerShell.Commands.Internal.Format.FrontEndCommandBase.ProcessRecord ()
   to System.Management.Automation.CommandProcessor.ProcessRecord ()

Inner Exception: The operation is not valid due to the current state of the object.
Of type: System.InvalidOperationException
Stack trace:
   to System.Management.Automation.MshCommandRuntime.ThrowTerminatingError (ErrorRecord ErrorRecord)

当不使用-Recurse时,代码可以工作。

最佳答案

虽然我无法仅用这一个命令在此处重现该错误,但该错误看起来像是由于 PowerShell 格式化子系统无法处理多个对象类型(由于单个格式化操作)而导致的错误。与人们的想法相反 - Format-table实际上结果对象和 Out-Default输出端自动执行的操作将会丢失。

我想知道执行此脚本是否对您本身不起作用,或者只是在较大脚本的上下文中出现问题?

我首先尝试的是附加 | Out-String | Out-Default在管道的末端。其实甚至| Out-String应该有帮助。

关于c# - 由于使用 sitecore 的对象的当前状态,该操作无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35212429/

相关文章:

java正则表达式查找第一个和最后一个字符

c - 可以用尾递归在C中生成加泰罗尼亚数字吗?

c# - 何时在 DbContext 构造函数中提供 DbContextOptions 与 OnConfiguring?

c# - 如何在 asp.net 中实现 "Add to clipboard"功能

powershell - 函数完成后 Import-PsSession 不可用

windows - 通过cmd/batch/powershell启用Windows 10内置热点

java - 通过 Java 的远程 Powershell 脚本

使用递归函数反转字符串的概念

c# - Azure 中跨上下文 LINQ 加入?

c# - 使用C#在ASP.NET中的YouTube视频播放器