Update Active Directory Users in Bulk from CSV

PowerShell V2 script to update Active Directory users from a CSV file. Only specified fields in the CSV that are not missing update the users. The value "<delete>" flags to clear the attribute. Attributes are not updated if the value in the CSV matches the existing value in AD.

5 Star
1,909 times
Add to favorites
Active Directory
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • Update users
    2 Posts | Last post May 09, 2018
    • what is wrong?
      my csv:
      my scripts:
      $plik = import-csv c:\skrypt\test.csv
      $plik | foreach {
      $user = Get-aduser -Filter {UserPrincipalName -like "*"}
      Set-aduser -Filter $user.UserPrincipalName -replace {-givenname -surname}
    • I want to change the uppercase and lowercase letters in the givenname and mail
  • Errors with some attributes
    1 Posts | Last post April 03, 2018
    • I was testing this out with a large bulk update I need to perform and noticed that I was unable to update the "office" filed of AD.  After doing a fair amount of isolating I learned that the syntax set-aduser was not working with a -replace.  Since my need was a one time use case, I used the code below.  I hope someone can update the script to reflect this for some of the set-aduser parameters or that the code is useful when someone else encounters this error.
      $Users = Import-Csv ".\users.csv"
      ForEach ($User In $Users)
          $UserID = $User.UserID
          $office = $User.office
          Set-ADUser -Identity $UserID -office $office
          Echo $userID $office
  • issue wirh script
    1 Posts | Last post March 26, 2018
    • Thanks for posting this - supremely helpful.
      I'm having an issue when trying to run the script with the $Update = $False set. On every user I get prompted for a value 
      -Value : The term '-Value' is not recognized as the name of a cmdlet, function, script file, or 
      operable program. Check the spelling of the name, or if a path was included, verify that the path 
      is correct and try again.
      At line:470 char:21
      +                     -Value "    Attributes could be replaced: $NumReplace"
      +                     ~~~~~~
          + CategoryInfo          : ObjectNotFound: (-Value:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
      cmdlet Add-Content at command pipeline position 1
      Supply values for the following parameters:
  • error
    1 Posts | Last post December 19, 2017
    • hi its giving me the error 
      Error Message: Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Properties'. Specified method is not supported.
  • Modification for LDAP Attributes + Alternates
    1 Posts | Last post November 22, 2017
    • Hey Richard,
      I am working on an integration that is to use a source of record that has basic employee information, but the database/exported CSV does not contain uniquely identifiable information that is also present on AD. I need to be able to match the users by first and last names that are active (possibly that are active(email?)), followed by adding/updating about 20 ldap attributes. I don't even believe I require the use of the 5 powershell fields. 
      Do I create the ldap fields at top of the file and as well as between lines 279-336? Are there additional modifications to this file aside from the block found in 241-359?
  • Run as another User
    1 Posts | Last post October 24, 2017
    • Hi,
      Sorry if very simple one but how can we run this script as different user?
  • CSV Set Up
    5 Posts | Last post October 12, 2017
    • I am testing the script just by trying to update the eMail Address of a user. 
      The scripts comes back with the failure:
      Field EmailAddress ist not in the csv file. 
      Script Aborted
      CSV file looks like this
      Now this is probably a misunderstanding on my site but... how do you expect the CSV to look like? 
    • This also comes with the error message:
       $CsvFields = $Users | Get-Member -MemberType noteproperty | Select Na ...
      +                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
          + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
    • Sorry for the delay. EmailAddress is the not LDAPDisplayName of an attribute of users, or one of the PowerShell properties supported by this script. The reason this property is not supported is because the EmailAddress property is simply a copy of the mail attribute of user objects. Instead of specifying the field "EmailAddress", use "mail" instead.
      I will do more testing when I get a chance, but I believe this accounts for your experience.
    • I do not get your error message when I use your csv file. The statement to populate $CsvFields works fine for me. But an error is raised later because EmailAddress is not recognized as the LDAPDisplayName of an attribute of users. It would work if the csv used the field name "mail" instead, and the array $Fields in the script defined the field "mail".
    • Hi, thanks for the answer. 
      I am wondering if I am doing something very obvious wrong, but I can´t get it working. 
      $Fields = @("mail")
      CSV = 
      Failure Message:
      Field mail is not in the CSV file
      Script Aborted.
      How does the CSV file has to look like for this to work? 
      Thanks a lot.
  • Facing issues | scipt is not updateing the attributes
    2 Posts | Last post April 27, 2017
      kindly check issues at https://social.technet.microsoft.com/Forums/windowsserver/en-US/c918b6d5-9998-4e2b-930a-7a270ef3a6ab/update-custom-and-other-attribute-of-user-in-ad-through-csv-file?forum=ADFS
    • In that thread you used $Update = $False when you ran the script, so it logged what the script would do, but did not actually update anything. I advised you to use $Update = $True and run the script again.