【发布时间】:2014-10-17 21:42:04
【问题描述】:
我正在编写一个 Powershell 脚本,该脚本基于 XML 配置文件询问 Active Directory,如下所示:
<domains>
<domain name="DOMAIN.INTERNAL" exclude="false">
<orgunit name="OU1" exclude="false"/>
<orgunit name="OU2" exclude="false">
<orgunit name="OU3" exclude="false"/>
<orgunit name="OU4" exclude="false"/>
<orgunit name="OU5" exclude="true"/>
</orgunit>
<host name="HOST1" exclude="false"/>
<host name="HOST2" exclude="true" />
<host name="HOST3" exclude="true" />
</domain>
<domain name="SUB.DOMAIN.INTERNAL" exclude="false">
<orgunit name="OU6" exclude="false">
<orgunit name="OU7" exclude="false">
<orgunit name="OU8" exclude="false">
<host name="HOST4" exclude="false" />
</orgunit>
</orgunit>
</orgunit>
<host name="HOST5" exclude="false"/>
<orgunit name="OU7" exclude="true" />
</domain>
</domains>
我正在加载 xml 文件,设置 xpath,然后选择没有子节点的 orgunit 节点:
$currentPath=Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
[xml]$configFile = Get-Content "$currentPath\WindowsUpdateOMatic.xml"
foreach ($domain in $configFile.domains.domain) {
$xpath = ("/domains/domain[@name=`"") + ($domain.name) + ("`"]//orgunit[@exclude=`"false`"][not (*)]/@name")
foreach($node in Select-Xml -Xpath $xpath $configFile){
# Find parent nodes
$node.Node.ParentNode
}
}
我的计划是遍历父组织单位节点,以便创建 OU 的完整可分辨名称,例如"OU=bar,OU=foo,DC=sub,DC=domain,DC=internal"。
然后我可以查询活动目录中的 OU 并检索其中的主机。
问题是,$node.Node.ParentNode 的值没有返回任何东西。尝试了各种方法,我确实让它返回“InputStream”,但我现在无法重现它。
我对 Powershell 还很陌生,我很欣赏它看起来我可能会在走路之前尝试跑步。
【问题讨论】:
标签: xml powershell