在 Powershell 工作流中解析 XML

Parsing XML in Powershell Workflow

我正在尝试从 Powershell 工作流中的 XML 文件中读取数据。 在普通的 Powershell 脚本中,我会将文件加载到 XML 对象中:[xml]$object = Get-Content $xmlPath。工作流似乎不喜欢这些对象,并且在任何检查点上都失败并显示错误:

The input objects cannot be serialized. Serialized data is required to suspend 
and resume workflows. To resolve the error, verify that the values of all 
variables and parameters are of types that can be serialized.
+ CategoryInfo : InvalidResult: (:) [], SerializationException
+ FullyQualifiedErrorId : JobStatusFailed

Powershell 是否有另一种解析方法 XML 与 Workflow 配合得很好?

谢谢

Workflow 中的操作存在限制,因此,应将一些 PowerShell 代码放入 InlineScript 以避免此限制:

workflow Parse-Xml {
    $xmlPath = "...."
    $xml = InlineScript {
       [xml] Get-Content $Using:xmlPath
    }

    $xml
}

Parse-Xml