Solved

Powershell script : Get-ADOrganizationalUnit in windows list box

Posted on 2016-09-09
2
124 Views
Last Modified: 2016-09-09
Dear All,

I have this structure in my AD

DC=lan
            DC=MyDomain
                                      OU=Root
                                                      OU=ou1
                                                              OU=ou11
                                                              OU=ou12
                                                      OU=ou2
                                                              OU=ou21
                                                              OU=ou22
                                                      OU=ou3
                                                              OU=ou31
                                                              OU=ou32

I would like to use the cmdlet Get-ADOrganizationalUnit to display ou1, ou2 and ou3 only (not the sub OU) in a windows list box in order to select them for next action.
I can't see how to achieve this?

Thks

JJC
0
Comment
Question by:celmajj
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41791457
You can use Get-ADOrganizationalUnit with -SearchScope parameter..
Import-Module ActiveDirectory
Get-ADOrganizationalUnit -F * -SearchScope OneLevel -SearchBase "OU=Root,DC=MyDomain,DC=lan" | Select -exp Distin*

Open in new window

For selecting Items From a List Box, refer following article..
https://technet.microsoft.com/en-us/library/ff730949.aspx
0
 

Author Comment

by:celmajj
ID: 41791499
good.

Thks you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now