Problem
You want to create a user account in a specific OU.
Solution
To create a user in a container, use the [adsi] type shortcut to bind to the OU in Active Directory, and then call the Create() method: $salesWest = [adsi] "LDAP://localhost:389/ou=West,ou=Sales,dc=Fabrikam,dc=COM"
$user = $salesWest.Create("User", "CN=MyerKen") $user.Put("userPrincipalName", "Ken.Myer@fabrikam.com") $user.Put("displayName", "Ken Myer") $user.SetInfo()
Discussion
The solution creates a user under the Sales West organizational unit. It sets the userPrincipalName (a unique identifier for the user), as well as the user’s display name.
When you run this script against a real Active Directory deployment (as opposed to an ADAM instance), be sure to update the sAMAccountName property, or you’ll get an autogenerated default.