当我使用 URL 连接到 HP ILO 时,http://ilo-ip/xmldata?item=全部 http://ilo-ip/xmldata?item=All它返回以下格式的 XML 文件。
<?xml version="1.0" ?>
- <RIMP>
- <HSI>
<SPN>ProLiant DL385 G1</SPN>
<SBSN>ABCDEFG</SBSN>
<UUID>123456789</UUID>
</HSI>
- <MP>
<ST>1</ST>
<PN>Integrated Lights-Out (iLO)</PN>
<FWRI>1.82</FWRI>
<HWRI>ASIC: 2</HWRI>
<SN>ILOABCDEFG</SN>
<UUID>ILO1234545</UUID>
</MP>
</RIMP>
是否有任何 powershell 命令/脚本可以从 Web URL 读取 XML 数据?
PowerShell 使用 .Net 框架 XmlDocument,因此您可以调用 load 方法将 xml 加载到 XmlDocument 对象中,如下所示:
#Option 1
$doc = New-Object System.Xml.XmlDocument
$doc.Load("http://ilo-ip/xmldata?item=All")
#Option 2
[xml]$doc = (New-Object System.Net.WebClient).DownloadString("http://ilo-ip/xmldata?item=All")
# Your XML will then be in the $doc and the names of the XML nodes can be used as
# properties to access the values they hold. This short example shows how you would
# access the value held in the SPN nodes from your sample XML
Write-Host $doc.RIMP.HSI.SPN
如果您在加载 XML 后寻找有关使用 XML 的更多信息,请查看Tobias Weltner 博士的电子书 http://powershell.com/cs/blogs/ebook/在 PowerShell.com 上,第14章 http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-14-xml.aspx涵盖 XML。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)