M
M
MrDywar Pichugin2014-11-16 19:14:21
PowerShell
MrDywar Pichugin, 2014-11-16 19:14:21

How to get a list of child OUs via PowerShell?

Hello.
There is one main name "OU=Company, DC=Site, DC=local".
It is required to get a list of all its child OUs, and all groups and users included in them. PowerShell works through "Import-Module ActiveDirectory".
Example OU=x3, OU=x2, OU=x1, OU=Company, DC=Site, DC=local.
Any ideas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nikitin, 2014-11-17
@Dywar

$OU = Get-ADOrganizationalUnit -SearchBase "OU=Company, DC=Site, DC=local" -Filter *
$Users = $OU | ForEach-Object {Get-ADUser -SearchBase $_.DistinguishedName -Filter *}
$Groups = $OU | ForEach-Object {Get-ADGroup -SearchBase $_.DistinguishedName -Filter *}
The $OU, $Users and $Groups variables will contain what you need.

G
God Emperor, 2015-03-31
@God-emperor

To work with Active Directory, I recommend using QAD-cmdlets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question