加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

如何使用PowerShell从Web读取XML文件

发布时间:2020-12-14 23:48:14 所属栏目:资源 来源:网络整理
导读:当我使用URL连接到HP ILO时,http://ilo-ip/xmldata?item=All将返回以下格式的XML文件. ?xml version="1.0" ? - RIMP- HSI SPNProLiant DL385 G1/SPN SBSNABCDEFG/SBSN UUID123456789/UUID /HSI- MP ST1/ST PNIntegrated Lights-Out (iLO)/PN FWRI1.82/FWRI H
当我使用URL连接到HP ILO时,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的更多信息,请查看PowerShell.com上的Dr. Tobias Weltner’s eBook,chapter 14涵盖XML.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读