Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • 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 2012
    • 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 / New-ADUser: Bulk Creating AD Users Using PowerShell

March 26, 2019 Active DirectoryPowerShell

New-ADUser: Bulk Creating AD Users Using PowerShell

The easiest way to create a new user object in the Active Directory domain is to use MMC graphical snap-in ADUC (Active Directory Users and Computers). But if you need to create multiple user accounts in the domain, doing it manually can be a tiresome task for an administrator. In this article, we’ll consider an example automating the creation of user accounts in AD using the New-ADUser PowerShell cmdlet.

Contents:
  • Using New-ADUser Cmdlet to Create New Active Directory User Account
  • Bulk Create AD Users from a CVS File Using PowerShell Script

Using New-ADUser Cmdlet to Create New Active Directory User Account

New-ADUser cmdlet is a part of Active Directory for PowerShell module. To use this module, you must install RSAT version corresponding to your OS version and enable Active Directory Module for Windows PowerShell component.

To import the module to your PowerShell session, run this command:

Import-Module activedirectory

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

Get-Command New-ADUser –Syntax

New-ADUser powershell cmdlet In the minimum version, to create a new account it’s enough to specify just the name of the AD user:
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 and is disabled. To use this account, you must enable it (Enable-ADAccount cmdlet), set its password (Set-ADAccountPassword cmdlet) and/or other attributes (if necessary).

To create a full-featured user account in the specific AD container of the domain (OU)  with the password and immediately enable the user’s object, use this command:

New-ADUser -Name "Albert Schmidt" -GivenName "Albert" -Surname "Schmidt" -SamAccountName "a.schmidt" -UserPrincipalName "a.schmidt@woshub.com" -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 will prompt you to set a password (protected) for a new user at once.

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 get the information about the created domain user object with Get-ADUser cmdlet:

Get-ADUser a.schmidt

Bulk Create AD Users from a CVS File Using PowerShell Script

If you have to create multiple Active Directory users at once, it’s easier to save the list of users in the format of CSV (Excel) file and then run a special PowerShell script. In this file, you must fill in all significant user attributes.

For example, my Excel file of users consists of 8 columns and has the following header format:

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

Fill in the user data and save the Excel file into the CSV format with commas as separating character. The encoding must be set to UTF-8 (it’s important!). The values of the OU column contain commas, so you must use double quotes.

Create New Active Directory Users with Excel and PowerShell

Now you can import this CSV file (create_new_ad_users.csv) and create new users in the AD domain. The code of the ready PowerShell script is shown below:

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

Note. If you are using “;” as a separating character in your CSV file, add -delimiter “;” argument to your Import-Csv cmdlet.


Import-Module activedirectory
Import-Csv "C:\ps\create_new_ad_users.csv" | ForEach-Object {
$upn = $_.SamAccountName + “@woshub.com”
$uname = $_.LastName + " " + $_.FirstName
New-ADUser -Name $uname `
-DisplayName $uname `
-GivenName $_.FirstName `
-Surname $_.LastName `
-OfficePhone $_.Phone `
-Department $_.Department `
-Title $_.JobTitle `
-UserPrincipalName $upn `
-SamAccountName $_.samAccountName `
-Path $_.OU `
-AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -Enabled $true
}

Create new Active Directory users with a PowerShell script

After you have run the script, open the ADUC console, expand the specified AD container and make sure that new user accounts have appeared in the AD. (You can track user account creation in the AD accounts as follows: Get Active Directory Accounts Created in the Last X Hours / Days.)

new user in active directory

You can add the created accounts to the specific AD group using Add-AdGroupMember cmdlet. To do it, modify the script by adding this line to the For-Each loop:

Add-AdGroupMember -Identity AllowInternetAccess-Members $_.samAccountName

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

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

6 comments
0
Facebook Twitter Google + Pinterest
previous post
DistributedCOM Error 10016 in Windows: The Application-specific Permission Settings do not Grant Local Activation Permission
next post
Converting SCCM WQL Query to SQL

Related Reading

Create Organizational Units (OU) Structure in Active Directory...

May 17, 2022

Windows Security Won’t Open or Shows a Blank...

May 17, 2022

How to Manually Install Windows Updates from CAB...

May 16, 2022

Deploying Software (MSI Packages) Using Group Policy

May 12, 2022

Enable or Disable MFA for Users in Azure/Microsoft...

April 27, 2022

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 7
  • Windows Server 2019
  • Windows Server 2016
  • Windows Server 2012 R2
  • PowerShell
  • VMWare
  • Hyper-V
  • MS Office

Recent Posts

  • Create Organizational Units (OU) Structure in Active Directory with PowerShell

    May 17, 2022
  • Windows Security Won’t Open or Shows a Blank Screen on Windows 10/ 11

    May 17, 2022
  • How to Manually Install Windows Updates from CAB and MSU Files?

    May 16, 2022
  • RDS and RemoteApp Performance Issues on Windows Server 2019/2016

    May 16, 2022
  • Deploying Software (MSI Packages) Using Group Policy

    May 12, 2022
  • Updating VMware ESXi Host from the Command Line

    May 11, 2022
  • Enable or Disable MFA for Users in Azure/Microsoft 365

    April 27, 2022
  • Fix: You’ll Need a New App to Open This Windows Defender Link

    April 27, 2022
  • How to Reset an Active Directory User Password with PowerShell and ADUC?

    April 27, 2022
  • How to Completely Uninstall Previous Versions of Office with Removal Scripts?

    April 26, 2022

Follow us

woshub.com

ad

  • Facebook
  • Twitter
  • RSS
Popular Posts
  • How to Configure Google Chrome Using Group Policy ADMX Templates?
  • Allow RDP Access to Domain Controller for Non-admin Users
  • How to Find the Source of Account Lockouts in Active Directory domain?
  • Get-ADComputer: Find Computer Details in Active Directory with PowerShell
  • Deploy PowerShell Active Directory Module without Installing RSAT
  • Managing User Photos in Active Directory Using ThumbnailPhoto Attribute
  • Changing Desktop Background Wallpaper in Windows through GPO
Footer Logo

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


Back To Top