How to create User Account using PowerShell in Active Directory. I’m using Windows Server 2012 R2, but this article will work with Windows Server 2008 to Server 2012 R2 or Server 2016.
A simple description about PowerShell. Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and CIM enabling management of remote Linux systems and network devices.
So if you have problem with creating objects in Active Directory with GUI, read the article: How to Create Objects in Active Directory?
Create User Account using PowerShell
In Windows Server run PowerShell and import Active Directory module or run Active directory module for Windows PowerShell from Tools in Server manager dashboard.
Type ‘Import-Module activedirectory’ and press enter to import the AD PowerShell module. This action will load all Active Directory commands for using in the current PowerShell window.
If you close the current PowerShell window, the Active Directory module will also exit and unload from PowerShell.
Type Get-Module and press enter to insure that module loaded successfully.
To see and list all active directory commands (CmdLet), just type ‘Get-Command -Module activedirectory’ and press enter then once explore all commands.
We need to create User Account with New-ADUser command. Type the below command and press enter.
PS C:\> New-ADUser -Name “Mehdi Hussaini” -GivenName Mehdi -Surname Hussaini -SamAccountName Mehdi -UserPrincipalName Mehdi@technig.local -AccountPassword (ConvertTo-SecureString -AsPlainText “PassW0rD” -Force ) -Enabled $true -ChangePasswordAtLogon $true
To get help for a command type ‘Get-Help New-ADUser -full’ or –example. The –full option will show you by details but the –example just show some examples for command.
To see if the user (Hehdi) has created or not, simply type ‘Get-ADUser -Identity Mehdi’ and press enter.
For getting full information about a user, type ‘Get-ADUser -Identity -Properties *’ then press enter.
That’s all, simple and easy. But it’s better to know the below Active Directory CmdLets for managing user account also.
1. To enable an Account type: ‘Enable-ADAccount -Identity mehdi’. This will enable the disabled user account immediately.
2. Disable an Account: ‘Disable-ADAccount -Identity Mehdi’
3. Reset the password of an account.
PS C:\> Set-ADAccountPassword -Identity mehdi -Reset
Please enter the desired password for ‘CN=Mehdi Hussaini,CN=Users,DC=Technig,DC=local’
Repeat Password: ********
4. Remove a User Account: ‘Remove-ADUser -Identity Mehdi’
OK. Now you can create, modify, enable, disable, and delete a user account from active directory with Windows PowerShell within Windows Servers. Hope you enjoy to create user account using PowerShell