看起来“set”也是XmlElement或Array对象中的一个方法。不带括号的方法名将显示定义。即使引用set也无济于事。我不确定另一种解决方法。另外,在引号中加上#text,这样就不会被视为评论。您可以将foreach对象缩写为%,where对象缩写为?。
[xml]$xml = get-content file.xml
$xml.configure | foreach-object set | where-object Name -EQ KeyStorePath |
foreach-object '#text'
D:\VALUE\ADM\VALUE.keystore
$xml.configure.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
$xml.configure | get-member set
TypeName: System.Xml.XmlElement
Name MemberType Definition
---- ---------- ----------
Set Property System.Object[] Set {get;}
$xml.configure[0] -eq '' # ???
True
select-xml '/Configure/Set[@name="KeyStorePath"]' file.xml | % node
name #text
---- -----
KeyStorePath D:\VALUE\ADM\VALUE.keystore