在大多数情况下,PowerShell 使使用 XML 变得相当容易。但是,我在使用“点”表示法遍历 web.config 文件时遇到了问题。一切正常
Import-Module WebAdministration
$site = get-website | ? { $_.name -eq "My Website - 80" }
$WebConfigFile = $site.physicalPath + "\web.config"
[xml]$WebAppXml = Get-Content $WebConfigFile
$webAppXml.configuration.system.web
在最后一行,PowerShell 使用智能感知填充 system.web,但如果您尝试运行它,输出为空。我知道我可以使用 Xpath 或 .NET Xml 对象,但如果没有必要,我宁愿不用。
最佳答案
$webAppXml.configuration.'system.web'
关于xml - 您如何使用 PowerShell 的 . (点)符号遍历元素名称中带有句点的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6526865/