How to create Active Directory user account with powershell
I am constantly setting up research and development environments that require active directory accounts. Since we place these environments in isloated networks each environment needs its own active directory. How can I create a new active directory account using powershell.
Solution 1:
I'm not sure if you are looking for a script that will take a list of names, passwords, etc, but the following command works to create one new user. UserPrincipalName is optional. In this case, email is not used.
New-ADUser -SamAccountName nnn2 -Name "nnn2" -UserPrincipalName nnn2@jj -AccountPassword (ConvertTo-SecureString -AsPlainText "somePassword" -Force) -Enabled $true -PasswordNeverExpires $true -Path 'CN=Users,DC=jjdomain,DC=net'
If you wish to create a user in a trusted domain, add -server dns.domain to above command
Solution 2:
I would recommend investigating Quest's AD cmdlets:
http://www.quest.com/powershell/activeroles-server.aspx
A new AD user would be:
new-QADUser -name 'user1' -ParentContainer 'OU=companyOU,DC=company,DC=com' -samAccountName 'user1' -UserPassword 'P@ssword'
However, for 'pure' Powershell, Shay's suggestion of Idera's scripts would save you using additional cmdlets. Mind you, if you are to go to the trouble of downloading the scripts you might as well download the Quest cmdlets.