KB

Create an Active Directory User with PowerShell

PowerShell code to create a user account in Active Directory:

$objOU=[ADSI]"LDAP://OU=People,DC=contoso,DC=com"
$objUser=$objOU.Create("user","CN=Daniel Mundy")
$objUser.Put("sAMAccountName","daniel.mundy")
$objUser.SetInfo()

To find the LDAP name for attributes use the Attribute Editor tab in Active Directory Users and Computers.

You can see what attributes are populated for a user object with the following commands:

$objUser.psbase.properties
$objUser | get-member

After you create an account you'll need to set a password and enable the account.

$objUser.SetPassword("P@ssw0rd")
$objUser.psbase.InvokeSet("AccountDisabled",$false)
$objUser.SetInfo()