PowerShell List OU

PowerShell List All OUs – organizational units in your domain. Very handy if you need to print out your OU list or make use of it in a different script.

$Connect = "LDAP://localhost/DC=brilliantly,DC=easy"
$ads = [adsi] $Connect
$ads = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"")
$ads.PageSize = 25000
$ads.Filter = "(&(objectCategory=OrganizationalUnit))"
$ads.SearchScope = "Subtree"
$ads.FindAll() | foreach { $_.properties.canonicalname } | sort


brilliantly.com/Domain Controllers
brilliantly.com/IT Virtual Classroom Accounts
brilliantly.com/IT Virtual Classroom Accounts/Students

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki
No comments yet.

Leave a Reply