Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / Creating New User Accounts in Active Directory with ADUC and PowerShell

April 3, 2023 Active DirectoryPowerShellWindows Server 2019

Creating New User Accounts in Active Directory with ADUC and PowerShell

In this article, we’ll look at how to create new users in an Active Directory domain. You can create new user accounts in your domain using the graphical mmc snap-ins ( Active Directory Users and Computers dsa.msc and AD Administrative Center dsac.msc) or with PowerShell scripts.

Contents:
  • How to Create a New Active Directory User with ADUC?
  • New-ADUser: Creating Active Directory Users with PowerShell
  • Bulk Create Active Directory Users from CSV with PowerShell

How to Create a New Active Directory User with ADUC?

The easiest way to create a new domain user in Active Directory is to use the graphical ADUC mmc console.

  1. Open the Active Directory Users and Computers console by running the dsa.msc command;
  2. Select the Active Directory container (Organizational Unit) in which you want to create a new user account. Right-click on it and select New -> User;     create new user with aduc console
    To create new users in the domain, your account must be a member of the Domain Admins or Account Operators groups. Or you can manually delegate user creation permissions to other domain users and groups.
  3. Specify the user’s first name, last name, and full name, set userPrincipalName (user login name) and sAMAccountName. Click Next;create new ad user object wizard
  4. Then set the user password. set active directory user account password propertiesOn this form, you can additionally set the following options for the UserAccountControl attribute:
    User must change password at next logon;
    User cannot change password – only the administrator/account operator can change/reset the user password;
    Password never expires – user password will never expire (if this option is not enabled, then user password expiration is determined by the Active Directory domain password policy);
    Account is disabled – the user account in the domain is disabled and cannot be used to log in.
  5. Find the user in the ADUC console and open its properties. Here you can set additional user attributes: phone number, address, description, position, company (etc.), add them to AD groups and set other attributes on the Attribute Editor tab.ad user properties

You can create new AD users with similar settings by copying. This way of creating new users is suitable for creating another user from the same department, with the same set of permissions, address, and description.

copy active directory user

Click on the user and select Copy. When copying an AD user, the group membership, address (except street), useraccountcontrol attribute settings, organization settings, and a number of other attributes will be copied to the new user account.

New-ADUser: Creating Active Directory Users with PowerShell

Above, we showed you how to manually create a user in an Active Directory domain using the ADUC graphical snap-in. If you’re constantly adding new users to your domain, it’s much more convenient to automate this process using PowerShell.

You can use the New-ADUser cmdlet from the Active Directory for Windows PowerShell module to create user accounts in AD.

You can get the full syntax of New-ADUser cmdlet using the command:

Get-Command New-ADUser –Syntax

New-ADUser powershell cmdlet

In the simplest case, to create a new user account in AD, it is enough to specify only its name:
New-ADUser testuser1

create new ad user object using powershell

As you can see, a new user account has been created in the default Users container. This user is disabled by default. To use this account, you must enable it (Enable-ADAccount cmdlet), set its password (Set-ADAccountPassword cmdlet) configure other attributes (if necessary).

To create a new account in a specific Active Directory container of the domain (OU) with a password and enable it immediately, use the following command:

New-ADUser -Name "Albert Schmidt" -GivenName "Albert" -Surname "Schmidt" -SamAccountName "a.schmidt" -UserPrincipalName "[email protected]" -Path "OU=Users,OU=Accounts,OU=Berlin,OU=DE,DC=woshub,DC=com" -AccountPassword(Read-Host -AsSecureString "Input Password") -Enabled $true

New-ADUser How to Create New Active Directory Users with PowerShell

The command prompts you to specify the password for the new user (the password is transmitted securely).

Note. The user’s password must comply with the domain password security policy by length, complexity, etc., otherwise, the cmdlet will return the error: New-ADUser: The password does not meet the length, complexity, or history requirement of the domain. You can use a ready-made PowerShell script to generate a complex password for each user.

You can get the information about the created domain user using the Get-ADUser cmdlet:

Get-ADUser a.schmidt

Bulk Create Active Directory Users from CSV with PowerShell

You can use PowerShell scripts to bulk create multiple users in an Active Directory domain. Consider a simple script to create user accounts from a list in a CSV file.

Fill in the required user attributes in the CSV (Excel) file format. For example, my Excel file with users has 8 columns and has the following header format:

FirstName;LastName;SamAccountName;Phone;Department;JobTitle;Password;OU

Save the Excel file as a CSV format with commas as delimiter. The encoding must be set to UTF-8 (it’s important!).

You can access values inExcel cells directly from PowerShell. I use a flat CSV file to simplify the script code in this example.

Create New Active Directory Users with Excel and PowerShell

Now you can import this CSV file (create_ad_users.csv) and create new users in the AD domain. See the following example of a PowerShell script that can be used to create users in Active Directory.

Bulk crea AD users using a CSV file and New-ADUser

Note.

  • Specify the name of the OU in which you want to create a new user account in the distinguishedName format ("OU=Users,OU=Munich,OU=DE,DC=woshub,DC=com" ). The value must be enclosed in double-quotes (because the string contains commas);
  • If “;” is used as the delimiter character for the CSV file, add the -delimiter ";" as an argument of your Import-Csv command;
  • The script checks if the user exists in the domain. If such an account already exists in the domain, a warning appears and prompts you to enter a unique sAMAccountName.


Import-Module activedirectory
$domain=“@woshub.com”
Import-Csv "C:\ps\create_ad_users.csv" | ForEach-Object {
$userSAM=$_.SamAccountName
if (@(Get-ADUser -Filter "SamAccountName -eq '$($_.SamAccountName)'").Count -ne 0) {
Add-Type -AssemblyName Microsoft.VisualBasic
$userSAM = [Microsoft.VisualBasic.Interaction]::InputBox("User $_.SamAccountName exists", 'Specify a new user SamAccountName', $_.SamAccountName)
}
$upn = $userSAM + $domain
$uname = $_.LastName + " " + $_.FirstName
New-ADUser -Name $uname `
-DisplayName $uname `
-GivenName $_.FirstName `
-Surname $_.LastName `
-OfficePhone $_.Phone `
-Department $_.Department `
-Title $_.JobTitle `
-UserPrincipalName $upn `
-SamAccountName $userSAM `
-Path $_.OU `
-AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -Enabled $true
}

bulk create new active-directory user from csv file with powershell script

In addition, you can save user creation info to a log file (an example of using log files in PowerShell scripts).

After running the script, open the ADUC console, expand the specified Active Directory OU, and make sure that new user accounts have appeared in the AD. You can track new user account creation events as follows: Get a list of Active Director use accounts created in the last X hours/days.

new user in active directory

You can immediately add new user accounts to the specific AD groups using the Add-AdGroupMember cmdlet. To do this, you need to slightly modify the script by adding this line to the For-Each loop:

Add-AdGroupMember -Identity AllowInternetAccess-Members $userSAM

Or you can set the user’s photo in AD to display it in Outlook and Lync using the Set-ADUser cmdlet:

Set-ADUser $userSAM -Replace @{thumbnailPhoto=([byte[]](Get-Content "C:\ps\l.wolf.jpg" -Encoding byte))}

6 comments
1
Facebook Twitter Google + Pinterest
previous post
The update is not applicable to your computer: Windows Update Error
next post
Tutorial: Install and Configure WSUS on Windows Server 2022/2019

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

6 comments

johan May 19, 2019 - 12:19 pm

script doesnt work

New-ADUser : Cannot validate argument on parameter ‘Path’. The argument is null or empty. Provide an argument that is not null or empty, and
then try the command again.
At line:14 char:7
+ -Path $_.OU `
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [New-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADUser

Reply
admin July 8, 2019 - 5:29 am

Show me your whole New-ADUser command

Reply
john December 31, 2021 - 7:46 am

Import-Csv “C:\Users\cammy\Desktop\BULKCREATE.xlsx” | ForEach-Object $upn = $_.SamAccountName + “@mydomain.com” $uname = $_.LastName + ” ” + $_.FirstName New-ADUser -Name $uname ` -DisplayName $uname ` -GivenName $_.FirstName ` -Surname $_.LastName ` -UserPrincipalName $upn ` -SamAccountName $_.samAccountName ` -Path $_.OU ` -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -Enabled $true

Reply
Battumur Munkhbaatar May 7, 2020 - 3:51 pm

New-ADUser : Cannot bind parameter ‘AccountPassword’. Cannot convert the
“User@cbps123!” value of type “System.String” to type
“System.Security.SecureString”.
At line:19 char:18
+ -AccountPassword $_.Password `
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ADUser], ParameterBindi
ngException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDi
rectory.Management.Commands.NewADUser

Reply
admin May 8, 2020 - 8:20 am

don’t use @ character as a part of user password in your powershell scripts. This is a special character. Or change it to `@

Reply
James September 7, 2020 - 9:26 pm

Do you need Excel running if you run this on the DC?

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Allow Non-admin Users RDP Access to Windows Server
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top