Seiji Amasawa
Seiji Amasawa

Reputation: 29

How to know who is the Manager in a particular OU in Active Directory

Juts want to know if anyone has already done this. How to know who is the Manager in a particular OU in Active Directory. I was able to get this in google but its not really what I need.

PS P:\> Get-ADOrganizationalUnit -Identity 'OU=Users,OU=Account Reps,OU=AR,DC=com' | Format-list *


City                     :
Country                  :
DistinguishedName        : OU=Users,OU=Account Reps,OU=AR,DC=com
LinkedGroupPolicyObjects : {cn={E8F56E1D-8B38-4698-B79B-76EB0150B8DA},cn=policies,cn=system,DC=nhsrx,DC=com}
ManagedBy                :
Name                     : Users
ObjectClass              : organizationalUnit
ObjectGUID               : 7dcd2bdd-fa1a-497f-8f5c-73260c3a0cb8
PostalCode               :
State                    :
StreetAddress            :
PropertyNames            : {City, Country, DistinguishedName, LinkedGroupPolicyObjects...}
AddedProperties          : {}
RemovedProperties        : {}
ModifiedProperties       : {}
PropertyCount            : 11

Upvotes: 0

Views: 160

Answers (1)

Ryan Bolger
Ryan Bolger

Reputation: 1295

With "Get-*" functions in the ActiveDirectory module, you generally have to ask for the specific attributes you care about because returning everything by default would put undue stress on your domain controllers. You do that with the -Properties parameter like this.

Get-ADOrganizationalUnit -Identity 'OU=Users,OU=Account Reps,OU=AR,DC=com' -Properties managedBy

For the managedBy property specifically, all you're going to get back is another DN value. So if you want the details for that object, you need to run a separate query for it.

$ou = Get-ADOrganizationalUnit -Identity 'OU=Users,OU=Account Reps,OU=AR,DC=com' -Properties managedBy
$manager = Get-ADUser -Identity $ou.managedBy

Keep in mind that OU managers can be set to object types other than users (like groups). So if you can't guarantee that, you might be better using Get-ADObject.

Upvotes: 1

Related Questions