I am writing a Powershell Script which interrogates Active Directory based on an XML configuration file that looks something like this:

```
<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>

```

I am loading the xml file, setting the xpath and then selecting the orgunit nodes that don't have children:

```
$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
    }
}

```

My plan is to iterate through the the parent org unit nodes so that I can create the full distinguished name of an OU, e.g. "OU=bar,OU=foo,DC=sub,DC=domain,DC=internal".

Then I can query the OU in active directory and retrieve host machines within it.

The trouble is, the value of $node.Node.ParentNode doesn't return anything. Trying various things I did get it to return "InputStream" but I can't reproduce that just now.

I'm fairly new to Powershell, I appreciate it looks like I'm probably trying to run before I can walk.