【问题标题】:Error deserializing Windows logs as PSObjects?将 Windows 日志反序列化为 PSObject 时出错?
【发布时间】:2020-06-30 20:25:41
【问题描述】:

尝试使用“PSSerializer.Deserialize(log) as PSObject;”反序列化 Powershell 日志但不断出错:

"System.Xml.XmlException: 'Element 'Objs' with namespace name 'http://schemas.microsoft.com/powershell/2004/04' was not found. Line 1, position 2.'"

日志示例:

"<Obj RefId=\"0\">
    <MS>
        <Obj N=\"PowerShell\" RefId=\"1\">
            <MS>
                <Obj N=\"Cmds\" RefId=\"2\">
                    <TN RefId=\"0\">
                        <T>System.Collections.Generic.List`1[[System.Management.Automation.PSObject, System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]</T>
                        <T>System.Object</T>
                    </TN>
                    <LST>
                        <Obj RefId=\"3\">
                            <MS> ......

【问题讨论】:

  • 你有一个位于 xml 根级别的数组吗?大多数使用 xml 格式的日志文件只是将数据附加到文件末尾。所以你需要使用带有 Fragment 选项的 XmlReader 来阅读。

标签: c# psobject xmlexception


【解决方案1】:

附加这个对我有用:

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"> 
..Log...
</Objs>

【讨论】:

    猜你喜欢
    • 2014-09-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多