Right now I have a single function that works as I expect to populate a root node with children gathered from AD , what I am attempting to do next is to populate each of these children with their children, I thought I could do achieve this by using
Code: Select all
treeview1.Nodes[1].Nodes[$TopLvlOU].Add("$Children")
The overall goal is to populate all OU's within our AD as they display in the AD Users & Computers tool, but in a friendly PowerShell GUI which will have buttons and such, but ideally dynamic as we need/remove OU's or re-arrange etc.
- Function BuildADTree
- {
- # Get the Top level AD structure as variable
- $TopAD = Get-ADOrganizationalUnit -SearchBase $BaseADOU -Filter * -SearchScope OneLevel | Select-Object -ExpandProperty Name
- Foreach ($TopLvlOU in $TopAD)
- {
- #Write-Host "$TopLvlOU"
- # Build the tree based off of node 1 (AD Base )
- $treeview1.Nodes[1].Nodes.Add("$TopLvlOU");
- }
- }