Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell script : Get-ADOrganizationalUnit in windows list box

Posted on 2016-09-09
2
Medium Priority
?
486 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 2000 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

963 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