Description:

A PowerShell V1 script to update users (or any class of Active Directory objects) in bulk from the information in a Microsoft Excel spreadsheet. Only single-valued string attributes are supported. The first row of the spreadsheet identifies the LDAP display names of the attributes to be updated. Each subsequent row provides information to update one user.

One attribute must uniquely identify the users, either distinguishedName or sAMAccountName. If there are columns for both distinguishedName and sAMAccountName, then distinguishedName is used to identify all of the objects and the value of sAMAccountName can be updated. The special value ".delete" in a cell means to remove any existing value for the attribute. A blank cell means to do nothing. Any other value is used to update the attribute. Values are only updated if they are different from the existing value. This version of the program only supports the updating of single-valued string attributes. Note that the description attribute is actually multi-valued, so is not supported by this version.

The program writes a log file to document which users are updated and any errors. The name and path of the spreadsheet file and the log file are both hard coded in the program. Be sure to modify the paths for your situation. As the program runs, a series of periods are displayed, one for each user processed, to indicate progress.

While the program was designed to update user objects, it can be used to update any class of Active Directory objects, even in the same spreadsheet. For example, you can update group, contact, or computer objects. Specify the attributes appropriate to the class of object. Remember that the sAMAccountName of computer objects is the NetBIOS name with a trailing "$" character. If the class of object does not have a sAMAccountName, such as contacts, then the objects must be identified by distinguishedName.

The program also demonstrates a method to trap errors in a PowerShell V1 script, using the Trap statement. Each Trap statement applies only to the scope within a code block. The program also attempts to release the Excel objects from memory.

UpdateUsers.txt <<-- Click here to view or download the program