I have a question about how to add users to AD using powershell, ive written a small script but i always get an error when i try to create a user.
$connection= "LDAP://ou=Users, dc="domain", dc="com"
$OU = [adsi] $Connection
$User = $OU.Create("user", "Test Person")
$User.Put("Firstname", "Test")
$User.Put("Surname", Person)
$User.Put("Email", "email@e.com")
$User.SetInfo()
I think my connection string is wrong, but i tried different ways already and still no success. This im trying locally. Need to get it working but then normally my AD is on different server, how to do it then?
Thanks in advance.
Here is another example (@Andy Arismendi was first) with some other details:
DirectoryEntry
constructorattribute=value
. In Active-Directory you can't choose the the attribute it's imposed by the schema. For auser
or aninetOrgPerson
it'sCN
for anorganizationalUnit
it'sOU
. In your case the name of the object isCN=Test Person
.You'll find here under the creation of an OU and a user.
Give this a try: