Updating AD Manager (from mail manager) Attribute from CSV using PowerShell

lucky alqodar 41 Reputation points
2023-01-12T02:34:00.15+00:00

Im trying to update the "Manager" attribute in Active Directory from a CSV file using PowerShell but i have attribute email manager only and user attribute from initials.

example csv

initials mailmanager title department
1234 jim@mail.com Accounting Finance
4321 jim@mail.com Procurement Finance
ForEach ($user in (import-csv -path "C:\script\testscript.csv"))
{
  $dn = $user.user
  $dm = $user.mail
  Get-AdUser -Filter { Initials -like $dn } | set-aduser -manager $user.mailmanager  -title $user.title -department $user.department 
}

error:

set-aduser : Identity info provided in the extended attribute: 'Manager' could not be resolved. Reason: 'Cannot find

an object with identity: 'jim@mail.com' under: 'DC=domain,DC=com'.'.

when i change mailmanager to samaccountname, powershell success.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,914 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Thameur-BOURBITA 32,586 Reputation points
    2023-01-12T12:58:45.7533333+00:00

    Hi,

    The manager attribute must contain the distinguishedName of the Manager not his mail or samaccountname.

    To resole your issue , you have to set the distinguishedName of the manager instead the mail.

    Manager attribute contains the distinguished name of the user who is the user's manager

    Please don't forget to mark helpdul reply as answer

    0 comments No comments