Solved

Powershell script : Get-ADOrganizationalUnit in windows list box

Posted on 2016-09-09
2
85 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A procedure for exporting installed hotfix details of remote computers using powershell
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

707 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

15 Experts available now in Live!

Get 1:1 Help Now