locked
Update AD from CSV RRS feed

  • Question

  • Hi

    I need to upgrade more than 1500 users the userprincipalname attribute.
    I have a CSV with this format:

    sAMAccountName, userprincipalname-OLD, userprincipalname-NEW
    Thor, thorelpoderoso@domain.local, thor-elpoderoso@domain.local
    Peter, petermax@domain.local, peter-max@domain.local
    July, julio-swar@domain.local, julio.swar@domain.local

    Can you help me please?, I know that it is asking much, but it is something urgent.

    Thanks mates!!

    Regards

    Monday, July 13, 2015 8:28 PM

Answers

  • Have you looked here - https://gallery.technet.microsoft.com/  There are all sorts of scripts already written to perform scripts against AD. You should be able to find one that does something similar to what you are looking to do and then modify it for your needs.

    . : | : . : | : . tim

    Monday, July 13, 2015 8:32 PM
  • Try something like this, if you are satisfied with the results, remove the -WhatIf switch and run it again. Also, not sure if the field userprinciplename-NEW will cause any issues, if so, then there is no need for the old userprinciplename, and you can just rename the header in the csv file to userprinciplename and update the script.

    Import-Csv C:\users.csv | Foreach {
      Set-AdUser -Identity $_.samAccountName -Replace @{UserPrincipleName = $_.UserPrincipleName-NEW} -WhatIf
    }


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.



    • Edited by clayman2 Tuesday, July 14, 2015 10:57 AM typo
    • Proposed as answer by AnnaWY Wednesday, July 15, 2015 3:18 AM
    • Marked as answer by ThorElPoderoso Wednesday, July 15, 2015 6:11 PM
    Monday, July 13, 2015 10:58 PM
  • You have a typo in your script: $_samAccountName
    I also think $_.UserPrincipleName-NEW needs quotes: $_.'UserPrincipleName-NEW'
    • Edited by Leif-Arne Helland Tuesday, July 14, 2015 5:34 AM
    • Proposed as answer by AnnaWY Wednesday, July 15, 2015 3:18 AM
    • Marked as answer by ThorElPoderoso Wednesday, July 15, 2015 6:10 PM
    Tuesday, July 14, 2015 5:29 AM
  • Thank you Leif, I fixed the one part, and as I stated I wasn't sure if the userprinciplename-new will cause an issue or not.

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Tuesday, July 14, 2015 10:57 AM

All replies

  • Have you looked here - https://gallery.technet.microsoft.com/  There are all sorts of scripts already written to perform scripts against AD. You should be able to find one that does something similar to what you are looking to do and then modify it for your needs.

    . : | : . : | : . tim

    Monday, July 13, 2015 8:32 PM
  • Try something like this, if you are satisfied with the results, remove the -WhatIf switch and run it again. Also, not sure if the field userprinciplename-NEW will cause any issues, if so, then there is no need for the old userprinciplename, and you can just rename the header in the csv file to userprinciplename and update the script.

    Import-Csv C:\users.csv | Foreach {
      Set-AdUser -Identity $_.samAccountName -Replace @{UserPrincipleName = $_.UserPrincipleName-NEW} -WhatIf
    }


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.



    • Edited by clayman2 Tuesday, July 14, 2015 10:57 AM typo
    • Proposed as answer by AnnaWY Wednesday, July 15, 2015 3:18 AM
    • Marked as answer by ThorElPoderoso Wednesday, July 15, 2015 6:11 PM
    Monday, July 13, 2015 10:58 PM
  • You have a typo in your script: $_samAccountName
    I also think $_.UserPrincipleName-NEW needs quotes: $_.'UserPrincipleName-NEW'
    • Edited by Leif-Arne Helland Tuesday, July 14, 2015 5:34 AM
    • Proposed as answer by AnnaWY Wednesday, July 15, 2015 3:18 AM
    • Marked as answer by ThorElPoderoso Wednesday, July 15, 2015 6:10 PM
    Tuesday, July 14, 2015 5:29 AM
  • Thank you Leif, I fixed the one part, and as I stated I wasn't sure if the userprinciplename-new will cause an issue or not.

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Tuesday, July 14, 2015 10:57 AM