如何使用 PowerShell 的 .(点)符号来遍历元素名称中带有句点的元素? [英] How can you use PowerShell's . (dot) notation to walk through elements with periods in the element name?

查看:36
本文介绍了如何使用 PowerShell 的 .(点)符号来遍历元素名称中带有句点的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数情况下,PowerShell 使处理 XML 变得相当容易.但是,我在使用点"符号遍历 web.config 文件时遇到了问题.一切正常

PowerShell makes working with XML fairly easy in most cases. However, I'm having trouble using the "dot" notation to walk through a web.config file. Everything works

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 对象,但如果我不需要,我宁愿不要.

On the last line, PowerShell uses intellisense to fill in system.web, but if you try to run it, the output is null. I know I can use Xpath or the .NET Xml objects, but I'd rather not if I don't have to.

推荐答案

$webAppXml.configuration.'system.web'

这篇关于如何使用 PowerShell 的 .(点)符号来遍历元素名称中带有句点的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆