无法使用powerhell提取XML节点的值
发布时间:2020-12-16 07:52:00 所属栏目:百科 来源:网络整理
导读:我想从xml文件中提取一些信息,并根据需要更新/创建一个应用程序池.这是我正在阅读的xml ?xml version="1.0" encoding="utf-8"?appPool name="MyAppPool" enable32BitAppOnWin64true/enable32BitAppOnWin64 managedPipelineModeIntegrated/managedPipelineMod
我想从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}; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |