Powershell: WPF/Treeview OU Selection Dialog

This is a self-contained organizational unit selection dialog box using powershell, xaml, wpf, and ADSI. Should be useful in any number of one off Powershell projects I imagine.

Because I was lego building my other bits of code together for this function I do a few slightly wonky things to populate the treeview properly. I first generate a json exportable object of the tree based on CanonicalName of the OUs. Then I recursively create listitems with the data using the CanonicalName as the tag data. Then I return distinguishedName as the results by converting the CN to DN again with a super fast and dirty hack function. So, goal acccomplished but in a round about way.

There are some also rather largish functions included in this example for what was to be the beginning of a generic ADSI library. I use these to query AD to avoid any dependencies on the AD cmdlets (at the expense of blowing up the overall script size by quite a bit).

Anyway, I uploaded this to the technet script gallery and my github repo.

Comments (1)

  1. 3:38 AM, 11/19/2017LS  / Reply

    Nice script thank you Zac. Line 88 in inner loop needs to be $firstset = $true. $false drops approx every 2nd OU from results. Best regards, L.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pingbacks (0)

› No pingbacks yet.


Get every new post delivered to your Inbox

Join other followers