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.
1 2 3 4 5 6 7 8 9 | #LDAP://localhost/DC=YOUR_DC,DC=YOUR_COMPUTER $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.PropertiesToLoad.AddRange((" canonicalName".split())) $ads .FindAll() | foreach { $_ .properties.canonicalname } | sort |
Result:.\list_ALL_OU_Doamin.ps1
brilliantly.com/Domain Controllers
brilliantly.com/IT Virtual Classroom Accounts
brilliantly.com/IT Virtual Classroom Accounts/Students
No comments yet.