What It Does
For each user the script creates the account in TargetOu, else the template user's OU, else the domain's default Users container. The sign-in name is AccountName and the user principal name is AccountName at UpnSuffix, defaulting to the template's suffix, else the domain's DNS name. The common name is DisplayName, or the given name and surname. The account is enabled, with a random 20-character password and a forced change at next sign-in.
With TemplateUser set, it copies the description, department, company, title, office, manager, street address, city, state, postal code and logon script path. It copies direct group memberships except groups flagged by adminCount or a protected SID pattern, which it skips with a warning. Review inherited access through nested groups. It does not copy the template's name, sign-in name, UPN, mail, password or account flags.
The password is never printed. In single-user mode it is written only to the RMM custom field named by ResultField, before the account is created, and the script refuses without one. OutputFormat Answer is refused for the same reason. A field holds one password, so in CSV mode every user gets a random password nobody knows and you issue the first real one with reset-ad-user-password.
Everything is checked before anything is created: sign-in name format, duplicates, the OU, the template, a clashing user principal name or name. A user whose sign-in name already exists is left alone and ends OK with Already exists, even its groups. In CSV mode a failing row does not stop the others, and the run ends ERROR listing the failures. DryRun lists what would be created.
Before You Run It
- Run it on a domain controller or a member server with the ActiveDirectory module (RSAT) and administrator rights.
- Pick a template user who is a clean example of the role, with only the groups the new person should have.
- In single-user mode create a secure RMM custom field first and pass it as ResultField.
- For a CSV, columns are AccountName (required), GivenName, Surname, DisplayName, TemplateUser and TargetOu. Try DryRun=true first.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
- What it changes: Creates AD users, adds them to the template's non-privileged groups and writes the first password to the RMM custom field.
- Restart: It never restarts the machine.
- Typical run: Under 20 seconds per user.
- Example answer: "Created jsmith in OU=Staff,DC=contoso,DC=com; must change password at first sign-in; password written to field NewUserPassword; added to 3 group(s)"
- Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- AccountName: The new sign-in name (sAMAccountName): 1 to 20 letters, digits, dot, dash or underscore. Required unless CsvPath is set. (Named AccountName, not UserName: Windows already has an environment variable called USERNAME.)
- GivenName: First name. Default empty.
- Surname: Last name. Default empty.
- DisplayName: Display name and common name. Default: "GivenName Surname", else AccountName. May not contain , = + < > # ; " or a backslash.
- TemplateUser: Sign-in name of an existing user to copy the OU, groups and attributes from. Default empty: nothing is copied.
- TargetOu: Distinguished name of the OU or container for the new user, e.g. "OU=Staff,DC=contoso,DC=com". Default empty: the template's OU, else the domain's Users container. It must exist.
- UpnSuffix: The part after the @ in the user principal name. Default empty: the template's suffix, else the domain's DNS name.
- CsvPath: Path of a CSV file of users to create (see above). Default empty: create the one user in AccountName.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.