Active Directory: Create a user with PowerShell


Windows Server 2012R2 Windows Server 2016 Windows Server 2019

This “how to” tutorial explains how to create users in Active Directory using the New-ADUser cmdlet in PowerShell

Create a user in Active Directory with PowerShell

Open a PowerShell window

On a domain controller, open a PowerShell command prompt.

PowerShell

Create the user using the New-ADUser cmdlet and validate the command

Example to create the user Jean DUPONT:

New-ADUser -Name "Jean DUPONT" -GivenName "Jean" -Surname "DUPONT" -SamAccountName "jdupont" -UserPrincipalName "[email protected]" -AccountPassword (ConvertTo-SecureString -AsPlainText "Pàssw0rd" -Force) -Enable $true -ChangePasswordAtLogon $true -Path "OU=Users,OU=IT,OU=Services,DC=LAB,DC=INTRA"
New-ADUser

Validate user creation with the Get-ADUser command

Enter the following command to display user information:

Get-ADUser -Identity "jdupont"
Get-ADUser

Paramètres de la commande New-ADUser

ParamètreDescription
-NameActive Directory object name
-GivenNameUser’s first name
-SurNameSurname
-SamAccountNameUser ID
-UserPrincipaleNameUser ID consisting of the UPN suffix (@domain.local)
-AccountPasswordUser password
-EnableThe account will be activated
-ChangePasswordAtLogonForce user change at next logon
-PathLocation in the directory, if not specified the user will be created in the Users container.

Source : https://docs.microsoft.com/en-us/powershell/module/addsadministration/new-aduser?view=win10-ps




Leave a Comment