【问题标题】:Parsing XML in Powershell Workflow在 Powershell 工作流中解析 XML
【发布时间】:2016-03-10 02:25:30
【问题描述】:

我正在尝试从 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 很好地结合?

谢谢

【问题讨论】:

    标签: powershell-4.0


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2010-12-15
      • 1970-01-01
      • 2017-05-18
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 2020-12-30
      相关资源
      最近更新 更多