Create AD User Remotely

by HighFiv3 at 2013-03-27 06:58:07

Hi Guy’s ,

i want to Create AD User Remotely in my Domain.
The script will be running on my Desktopcomputer not on the Server.

At the moment i have one Problem. I have no idea to move the AD User into a Group. How i can do this without Import the AD Module?
This my code:
$usersOU = [ADSI] "LDAP://cn=users,dc=domain,dc=TLD"
$newUser = $usersOU.Create("user","cn=$Name")
#$newUser = $usersOU.Create("user","cn=$kuerzel")
$newUser.put("givenname", "$Vorname")
$newUser.put("sn", "$Nachname")
$newUser.Put("displayName","$Vorname" + " " + "$Nachname")
$newUser.Put("sAMAccountName", $kuerzel)
$newUser.Put("userPrincipalName", "$upn")
$newUser.Put("ScriptPath","logon_ip.cmd")
$newUser.SetInfo()

$newUser.psbase.InvokeSet("AccountDisabled", $false)
$newUser.psbase.invoke("SetPassword","12345678")
$newUser.CommitChanges()
by coderaven at 2013-03-27 07:42:33
Using ADSI, to add a user to a group you need to connect to the group and call the add function there. See one of Don’s articles here

You may want to look into remoting or the PowerShell Web Access to get around using ADSI.
by HighFiv3 at 2013-03-27 08:21:37
I have not fount a Memberof variable with my ADSI-Editor… my DC is a 2008R2 is this maybe the problem?

Greetz
by coderaven at 2013-03-28 07:07:23
The memberof is not a variable of the ADSI user. You will see the Properties though.

$User.Properties["memberof"]

This article from Richard Siddaway explains it better.