Answer the question
In order to leave comments, you need to log in
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
$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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question