我想从xml文件中提取一些信息,并根据需要更新/创建一个应用程序池.这是我正在阅读的xml
<?xml version="1.0" encoding="utf-8"?> <appPool name="MyAppPool"> <enable32BitAppOnWin64>true</enable32BitAppOnWin64> <managedPipelineMode>Integrated</managedPipelineMode> <managedRuntimeVersion>v4.0</managedRuntimeVersion> <autoStart>true</autoStart> </appPool>
这是我正在尝试的:
#read in the xml $appPoolXml = [xml](Get-Content $file) #get the name of the app pool $name = $appPoolXml.appPool.name #iterate over the nodes and update the app pool $appPoolXml.appPool.ChildNodes | % { #this is where the problem exists set-itemproperty IIS:\AppPools\$name -name $_.Name -value $_.Value }
$_.Name返回节点的名称(即enable32BitAppOnWin64),这是正确的,但是.Value属性不返回任何东西.如何提取我想要的数据?
更正答案:
你想要$_.’#text’而不是$_.
另请考虑,它使用System.Xml.XmlElement对象上的InnerText属性:
$xml.appPool.ChildNodes | %{$.Name; $.InnerText};