How to Update Users Attributes in Local AD from CSV file with Powershell

Here is an example of CSV, please encode it UTF-8

JaneDoe,Jane Doe,JD,de,Jane,Leo,Doe,+49 30 1000000-104,8888888888,000007000,[email protected],Contoso Ltd,Muster Allee 121,Berlin,15014,IT,Accountant,Musterstra├če 17,MMustermann,55555555,

and here is the PS Code

Import-module ActiveDirectory
$users = Import-Csv "C:\temp\Attributes.csv"
foreach ($user in $users) {
    $props = @{
        identity    = $user.samaccountname
        DisplayName = if($user.DisplayName    ){$user.DisplayName    }else{$null}
        Country     = if($user.Country    ){$user.Country    }else{$null}
        givenName     = if($user.fname    ){$user.fname    }else{$null}
        OtherName     = if($user.OtherName    ){$user.OtherName    }else{$null}
        surname     = if($    ){$    }else{$null}
        Fax     = if($user.Fax    ){$user.Fax    }else{$null}
        OfficePhone     = if($user.OfficePhone    ){$user.OfficePhone    }else{$null}
        MobilePhone     = if($user.MobilePhone    ){$user.MobilePhone    }else{$null}
        EmailAddress     = if($user.EmailAddress    ){$user.EmailAddress    }else{$null}
        Company     = if($user.Company    ){$user.Company    }else{$null}
        Office     = if($user.Office    ){$user.Office    }else{$null}
        City     = if($user.City    ){$user.City    }else{$null}
        PostalCode     = if($user.postalCode    ){$user.postalCode    }else{$null}
        Department     = if($user.Department    ){$user.Department    }else{$null}
        Title     = if($user.Title    ){$user.Title    }else{$null}
        HomePage     = if($user.HomePage    ){$user.HomePage    }else{$null}
        streetAddress       = if($user.streetAddress      ){$user.streetAddress      }else{$null}
        Manager       = if($user.Manager      ){$user.Manager      }else{$null}
        Initials      = if($user.Initials      ){$user.Initials      }else{$null}
        HomePhone     = if($user.HomePhone      ){$user.HomePhone      }else{$null}
    set-aduser @props

Please Take these points in consideration 

  • For Manager The acceptable values for this parameter are:

A distinguished name
A GUID (objectGUID)
A security identifier (objectSid)
A SAM account name (sAMAccountName)

  • For Country please use the region code, in my case it “de” for Germany


Tech Blog
Login/Register access is temporary disabled