Library / Windows Server and AD

SERVER-004 · Script

Create and Configure Directory User

Creates one or many directory user accounts with name, OU, job details, manager and groups set.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Creates a single user from the settings below, or many users from a CSV file. Preview mode (default) checks every row and logs exactly what it would create, without changing anything. Apply mode creates the accounts, enabled, with a random password that must be changed at first sign-in, then adds the groups. Existing accounts are never changed; they are skipped and listed. Generated passwords are saved to a protected file that only SYSTEM and Administrators can read. They are never written to the log.

CSV columns (GivenName and Surname are required, the rest are optional): GivenName, Surname, SamAccountName, Path, Department, Title, Office, Company, Manager, EmployeeID, Email, Description, Groups (separate several groups with a semicolon)

Requirements

Windows PowerShell 5.1 and the ActiveDirectory module (RSAT). Rights to create users in the target OU and edit the listed groups.

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
CsvPathPath to a CSV file of users to create. Leave empty to create the single user below.
GivenNameFirst name, for a single user.
SurnameLast name, for a single user.
SamAccountNameSign-in name. Leave empty to build it from -NameFormat.
PathOU for new accounts, as a distinguished name. A Path column in the CSV overrides it.
NameFormatHow to build the sign-in name when none is given: first.last (default), flast, firstl or first_last.first.last, flast, firstl, first_lastfirst.last
UpnSuffixSign-in suffix, for example school.org. Default: the domain DNS name.
DepartmentDepartment, for a single user or as the default for CSV rows.
TitleJob title, for a single user.
OfficeOffice or building.
CompanyCompany or school name.
ManagerManager's sign-in name.
GroupsGroups to add every new user to.(none)
PasswordLengthLength of the generated first password. Default: 16.16
ChangeAtSignInYes (default) makes the user set a new password at first sign-in.Yes, NoYes
ServerOptional domain controller to use for every change.

Exit codes

  • 0 = All rows created (or would be created, in Preview)
  • 1 = Some rows were skipped or failed (see log)
  • 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. To undo an Apply run, delete the new accounts listed in the report (Remove-ADUser), then delete the protected password file in the Runbookia Secure folder.

Version and change log

VersionDateChanges
1.0.0November 2026First release.