无法使用powerhell提取XML节点的值

前端之家收集整理的这篇文章主要介绍了无法使用powerhell提取XML节点的值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从xml文件提取一些信息,并根据需要更新/创建一个应用程序池.这是我正在阅读的xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <appPool name="MyAppPool">
  3. <enable32BitAppOnWin64>true</enable32BitAppOnWin64>
  4. <managedPipelineMode>Integrated</managedPipelineMode>
  5. <managedRuntimeVersion>v4.0</managedRuntimeVersion>
  6. <autoStart>true</autoStart>
  7. </appPool>

这是我正在尝试的:

  1. #read in the xml
  2. $appPoolXml = [xml](Get-Content $file)
  3.  
  4. #get the name of the app pool
  5. $name = $appPoolXml.appPool.name
  6.  
  7. #iterate over the nodes and update the app pool
  8. $appPoolXml.appPool.ChildNodes | % {
  9. #this is where the problem exists
  10. set-itemproperty IIS:\AppPools\$name -name $_.Name -value $_.Value
  11. }

$_.Name返回节点的名称(即enable32BitAppOnWin64),这是正确的,但是.Value属性不返回任何东西.如何提取我想要的数据?

更正答案:

你想要$_.’#text’而不是$_.

另请考虑,它使用System.Xml.XmlElement对象上的InnerText属性

$xml.appPool.ChildNodes | %{$.Name; $.InnerText};

猜你在找的XML相关文章