Library / Windows Server and AD

SERVER-009 · Script

Update Directory User Attributes

Updates directory user details (title, department, phone, manager and more) from a CSV file.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Reads a CSV file with one row per user. One column identifies the user (SamAccountName by default); the other columns are the details to set. Only the columns listed below are accepted, so a typo cannot write to an unexpected attribute. Unknown columns are reported and skipped.

Department, Title, Company, Office, OfficePhone, MobilePhone, Manager, EmployeeID, EmployeeNumber, Description, StreetAddress, City, State, PostalCode, DisplayName, GivenName, Surname, Email, extensionAttribute1 through extensionAttribute15

Only values that are different from what is already in the directory are changed. Blank cells are left alone unless -ClearWhenBlank is used. Manager can be a sign-in name or a distinguished name. Preview mode (default) logs every change it would make. Apply makes the changes and saves a rollback CSV, in the same layout as the input, holding the old values. To undo, run the rollback file through this script with -ClearWhenBlank.

Requirements

Windows PowerShell 5.1 and the ActiveDirectory module (RSAT). Write rights on the attributes being changed.

How to run it

  • Run as: a service account with the directory rights the script lists, or SYSTEM on a domain controller or the server being checked
  • Run from: a domain-joined management server or admin workstation with the RSAT tools, as a scheduled task or from your management tool
  • Script type: PowerShell 5.1, 64-bit
  • User interaction: none; the script never prompts
  • Timeout: 30 minutes for large directories or many servers

Settings

NameWhat it doesOptionsDefault
ModePreview (default) or Apply.Preview, ApplyPreview
CsvPathCSV file to read.
IdentityColumnColumn that identifies each user: SamAccountName (default), UserPrincipalName, EmployeeID or Email.SamAccountName, UserPrincipalName, EmployeeID, EmailSamAccountName
ClearWhenBlankClear the attribute when a cell is blank. Off by default.False
ServerOptional domain controller to use for every change.

Exit codes

  • 0 = All rows processed
  • 1 = Some rows had unknown users, more than one match, or failed changes
  • 2 = Script error (see log)

Testing steps

  1. Run it first with the mode set to Preview on one test OU, test account or test server. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Preview mode changes nothing. Apply saves a rollback CSV with the old values in the same layout as your input. To undo, run that file back through this script with ClearWhenBlank turned on.

Version and change log

VersionDateChanges
1.0.0November 2026First release.