PowerShell event log xml xpath select not working

核能气质少年 提交于 2019-12-06 06:11:35

This is a classic problem when working with XML; your XML has default namespace (xmlns="...."). The element where the namespace defined and all it's descendants without prefix and without different default namespace declaration considered in the same namespace.

To be able to access elements in a namespace you have to declare a prefix that point to the namespace URI and use that prefix in your XPath query, for example :

.......
$ns = New-Object System.Xml.XmlNamespaceManager($x.NameTable)
$ns.AddNamespace("ns", $x.DocumentElement.NamespaceURI)
$x.SelectNodes("/ns:Event/ns:EventData", $ns)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!