Thursday, February 3, 2011

Active Directory - Bulk Company Update

I was wondering if there is a way to update the 'Company' field for a large group of users within Active Directory? I would like to match all users with a company ending in a certain string.

It would take way too long to change this for each user individually.

  • Write a powershell script to change it for all users where the company = the old company name to the new company name.

    kaerast : Well yeah, you probably could do something in powershell. But that in itself isn't a helpful answer - what are the powershell commands for searching and modifying users?
    jer.salamon : true but was pointing in a good direction thanks for the -1
    John Gardeniers : A cryptic reference to an an even more cryptic scripting language, with no real information about solving the problem is not a good answer - ever. I'll credit it to inexperience rather than downvote it.
    jer.salamon : Thanks its what I get for answering and driving
    jscott : *"...answering and driving"* -- As in *while* driving a motor vehicle? Please don't do that, it's incredibly dangerous to yourself and others on the road.
  • dsquery user -name * -limit 0 | dsmod user -company "%COMPANY%"
    

    Adjust the dsquery to target specific users as required.

    Edit: To match on a specific [sub-]string

    dsquery * -filter "&((objectCategory=Person)(objectClass=User)(company=*OLDCOMPANY))" -limit 0 | dsmod user -company "%NEWCOMPANY%"
    

    Adjust the *OLDCOMPANY regex to suit your needs.

    sysadmin1138 : +1 Dead simple, and should work great!
    JT.WK : Thanks for the suggestion - playing with it now. Can this be modified to only change users where the company ends with a particular string?
    jer.salamon : +1 I like dead simple
    jscott : @JT.WK: Updating my answer...
    squillman : +1 Very nice solution.
    JT.WK : Thanks a lot guys! You saved me hours or repetition! Cheers!
    Izzy : +1 Win. I was about to write the same thing using Find, DSQuery, DSGet, and DSMod - but yours is a much more elegant solution
    From jscott

0 comments:

Post a Comment