200mg
200mg

Reputation: 531

Adding manager attribute fails

I have a script that matches a contact based on an email in a csv, I can find the contact using a get-adobject -ldapfilter but when I try to add the contact as a manager the add fails stating it cannot find the contact. The contact it states it cannot find is clearly present in the directory.

This line will find the contact:

$rmanager = Get-ADObject -SearchBase 'OU=workplace,OU=Contacts,DC=office,DC=com' -ldapfilter "(&(objectclass=contact)(name=$fname*)(name=*$lname))" 

An example of the contact in question being found...

PS C:\temp> Get-ADObject -SearchBase 'OU=workplace,OU=Contacts,DC=office,DC=com' -ldapfilter "(&(objectclass=contact)(name=$fname*)(name=*$lname))"

DistinguishedName Name ObjectClass ObjectGUID 
----------------- ---- ----------- ---------- 
CN=Nick Hill,OU=workplace,OU=Contacts,DC=office,DC=com Nick Hill contact b649bd7e-aac9-4d4b-8203-b6a79f35b91

However, this line with the set-aduser will fail stating it cannot find the contact that clearly exists...

get-aduser -f {mail -eq $username} |set-aduser -Manager "$rmanager"



set-aduser : Identity info provided in the extended attribute: 'Manager' could not be resolved. Reason: 'Cannot find an object with identity: 'CN=Nick Hill,OU=Workplace,OU=Contacts,DC=office,DC=com' under: 'DC=Office,DC=com'.'.

Upvotes: 0

Views: 1861

Answers (1)

Bill_Stewart
Bill_Stewart

Reputation: 24565

I just tested this and it worked:

a. Get distinguishedName of contact:

$contactDN = Get-ADObject -LDAPFilter "(&(objectClass=contact)(givenName=firstname)(sn=lastname))"
  | Select-Object -ExpandProperty DistinguishedName

b. Get the user object and replace the manager attribute:

Get-ADUser username | Get-ADObject | Set-ADObject -Replace @{"manager" = $contactDN}

Upvotes: 1

Related Questions