在大多数情况下,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
Run Code Online (Sandbox Code Playgroud)
在最后一行,PowerShell使用intellisense来填充system.web,但是如果您尝试运行它,则输出为null.我知道我可以使用Xpath或.NET Xml对象,但如果我不需要,我宁愿不这样做.