Life of a Sysadmin

The occassional trials and tribulations of a jack of all tr ades sysadmin in a startup in Silicon Valley

June 2005

Making bulk changes in AD, or my windows has some icky command lines

I have an Active Directory with about 900 users. The vast majority (all but about 15) have a single mandatory roaming profile. Because of some inconsistencies in the creation of user accounts over the years, how the profile location is specified in an account varies. Some accounts have "\\servername\profiles\normal\" some have "%logonserver%\profiles\normal". I needed to standardize these to "\\newservername\profiles\normal\".

The easy way would be with the graphical tools. Select multiple users in Active Directory Users and Computers, right click, and select Properties.

With this form it is relatively trivial to change a huge number of accounts. While I changed nearly the profile path listing to "\\newservername\profiles\normal\", I changed some (those accounts that have their own profiles) to "\\newservername\profiles\%username%". There are a variety of other environment variables available.

The hard way would use the Directory Service command-line tools from Microsoft that were included with Windows 2003 Server. They are quite powerful tools that allow you to query, modify, add, or whatnot.

The command I ended up with, after a great deal of experimentation (most of it was simply getting comfortable with the tools and toying with examples provided in Microsoft's documentation), was

dsget group "CN=groupname,DC=ads,DC=example,DC=com" -members -expand | dsmod user -profile "\\servername\profiles\normal"

the dsget command returns one per line a list of users that belong to the group "groupname". dsmod takes that output and changes the profile setting.

Other interesting examples of the DS tools.

This will get you a list of all members (recursively expanded if you have nested groups) of group groupname.

dsget group "CN=groupname,DC=ads,DC=example,DC=com" -members -expand

To create a new user

dsadd user "cn=username,DC=ads,DC=example,DC=com"

Much of my experimentation with the DS tools was done with thoughts of finally scripting account creation floating through my head. Let me just slide this into a slot near the top of to do list.

[2005/06/16 | /software | permanent link]