Active Directory - Bulk updating user information using Excel.

AID: 1724
  • Status: Published

5950 points

  • Byxuserx2000
  • TypeTips/Tricks
  • Posted on2009-10-07 at 14:33:37
It happens to all of us.  Once in a while Active Directory information gets a little "out of date".  People tend to change departments, get married and change their last names, change cell phone numbers or change addresses.  Maintaining this information can be a challenge when you have a lot of users, but it can also be very beneficial to an organization as a whole.

This is my little "trick" to bulk updating user attributes and information in Active Directory, based on data from a Microsoft Excel sheet.  The sheet uses formulas to produce a command line.  The command line employs Dsquery.exe and Dsmod.exe, utility programs which are included in the Windows Server 2003 Administration Tools Pack.

An example of a command line to modify a user, using these tools, might look something like this.
dsquery user -samid "DJohns" | dsmod user -tel "555-555-5555"
                                    
1:

Select allOpen in new window


...so Dsquery.exe finds the user whose "samid" = djohns, and the "DistinguishedName" result is piped directly into Dsmod.exe where we use the telephone parameter with the new value.

To produce this command line in MS Excel, I primarily use the "Concatenate" function.
In a cell, you can type the formula =concatenate("foo","bar") and the result would be: foobar
This works on cells that have information too, for example =concatenate(A1,B1,C1) would join the strings that exists in cells A1, B1 and C1.

Example:  
=CONCATENATE("dsquery user -samid"," """,A2,"""," | dsmod user -tel ",B2)
                                    
1:

Select allOpen in new window



The result would be: dsquery user -samid "DJohns" | dsmod user -tel "555-555-5555"
That formula's resulting command line can then be copied and pasted directly into command prompt.

Another thing this formula must take into account is that some information might be left blank. For this scenario we wouldn't want to include that parameter in the final resulting command line, or we might not want to produce a command line at all.  To solve this problem we use the IF() function in Excel.  =IF({logical test},{value if true},{value if false})

Example using IF() with Concatenate():

=IF(b2="","",CONCATENATE("dsquery user -samid"," """,A2,"""," | dsmod user -tel ",B2))
                                    
1:

Select allOpen in new window


This means we only produce a command line if the phone number in B2 is not left blank.

A demonstration of a working example can be found in the attached file: XLS-Dsquery-Dsmod.xls

Pay close attention to the "notes" and use this at your own risk. Some logic is built in; for example, "description" is auto generated from other fields, as well as the "displayName".  The description field uses the "department" + "title" + "location", so if "DJOHNS" works in Human Resources, his title is Director, and his office is in Florida, his description becomes "Human Resources Director in Florida".

To use this sheet, simply populate it with user information, and then copy/paste the resulting command lines into the command prompt.  Take notice that the "DEFAULT VALUES" rows were put there to enable you to copy and paste them to rows below, when adding users, in order to transpose all of the formulas that are involved in this sheet. If a row is a "DEFAULT VALUE" row, the final command line formula will NOT produce a command line.  All of the columns that contain formulas are hidden, with the exception of the command line column.

This is the formula that produces the final command line:
=IF(A7="DEFAULT VALUES","",CONCATENATE("dsquery user -samid ",A7," | dsmod user",C7,E7,G7,I7,K7,M7,O7,Q7,S7,U7,W7,Y7,AA7,AC7,AE7,AG7,AI7,AK7,AM7))
                                    
1:

Select allOpen in new window



Minimum Requirements
Windows Server 2003 Administration Tools Pack - installed (Or, Windows Server 2008 which includes dsquery/dsmod)
Microsoft Excel Runtime - installed
Asked On
2009-10-07 at 14:33:37ID1724
Tags

dsmod

,

dsquery

,

excel

Topic

Active Directory

Views
5706

Comments

Author Comment

by: xuserx2000 on 2009-10-07 at 14:35:49ID: 4032

The functionality for setting a NEW password (-pwd), was intentionally left out of this sheet, but could be added if needed.

Expert Comment

by: omzz on 2010-04-21 at 12:40:53ID: 13658

There are some third party tools available to bulk create users and mailboxes.
One such tool is Synchronize from Imanami.

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Active Directory Experts

  1. mkline71

    412,697

    Wizard

    3,000 points yesterday

    Profile
    Rank: Genius
  2. dariusg

    163,412

    Guru

    0 points yesterday

    Profile
    Rank: Genius
  3. dvt_localboy

    136,278

    Master

    0 points yesterday

    Profile
    Rank: Sage
  4. demazter

    116,263

    Master

    0 points yesterday

    Profile
    Rank: Genius
  5. iSiek

    113,702

    Master

    0 points yesterday

    Profile
    Rank: Genius
  6. motnahp00

    92,762

    Master

    0 points yesterday

    Profile
    Rank: Sage
  7. acbrown2010

    81,763

    Master

    10 points yesterday

    Profile
    Rank: Genius
  8. Jmoody10

    71,214

    Master

    1,210 points yesterday

    Profile
    Rank: Wizard
  9. yo_bee

    68,718

    Master

    0 points yesterday

    Profile
    Rank: Guru
  10. kevinhsieh

    60,310

    Master

    0 points yesterday

    Profile
    Rank: Genius
  11. KenMcF

    56,098

    Master

    0 points yesterday

    Profile
    Rank: Genius
  12. snusgubben

    55,438

    Master

    0 points yesterday

    Profile
    Rank: Sage
  13. pwindell

    54,060

    Master

    2,800 points yesterday

    Profile
    Rank: Genius
  14. KCTS

    52,196

    Master

    0 points yesterday

    Profile
    Rank: Genius
  15. leew

    51,399

    Master

    0 points yesterday

    Profile
    Rank: Savant
  16. PrashantGirennavar

    46,884

    3,000 points yesterday

    Profile
  17. Neilsr

    46,472

    0 points yesterday

    Profile
    Rank: Genius
  18. xxdcmast

    42,972

    1,100 points yesterday

    Profile
    Rank: Genius
  19. Anuroopsundd

    38,834

    0 points yesterday

    Profile
    Rank: Sage
  20. dstewartjr

    37,595

    0 points yesterday

    Profile
    Rank: Genius
  21. RobSampson

    36,382

    0 points yesterday

    Profile
    Rank: Genius
  22. ve3ofa

    34,856

    1,800 points yesterday

    Profile
    Rank: Genius
  23. amitkulshrestha

    34,647

    0 points yesterday

    Profile
    Rank: Genius
  24. alanhardisty

    32,393

    0 points yesterday

    Profile
    Rank: Genius
  25. McKnife

    32,203

    2,000 points yesterday

    Profile
    Rank: Genius

Hall Of Fame