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使用Intellisense填充system.web,但如果您尝试运行它,则输出为空。我知道我可以使用Xpath或.NET Xml对象,但如果我不需要,我宁愿不要。
- $webAppXml.configuration.'system.web'