【发布时间】:2016-08-10 14:03:53
【问题描述】:
如何通过使用 PowerShell 从 XML 文件传递属性名称来获取属性值。例如,以下是XML文件内容
<?xml version="1.0" encoding="utf-8"?>
<MyProject>
<!-- My Comment Here -->
<MyPropertyGroup>
<PropertyID>2</PropertyID>
<PropertyName>ItsMyName</PropertyName>
</MyPropertyGroup>
<MyPropertyGroup>
<MobileNo>3</MobileNo>
<NickName>ItsMyNickName</NickName>
</MyPropertyGroup>
</MyProject>
我尝试如下:
[xml]$file = Get-Content 'C:\Temp\MyTest.xml'
$file.ChildNodes[1].GetElementsByTagName("PropertyName")
但它返回结果如下:
#文本 ----- 它我的名字
我想将ItsMyName 作为结果存储到变量中。
【问题讨论】:
标签: xml powershell