Function CreateAccount($UserName, $FullName, $ADsPath)
$OU = GetObject($ADsPath)
$UserObj = $OU.Create("User", "cn=" + $FullName)
$UserObj.Put("sAMAccountName", $UserName)
$UserObj.Put("givenName", $fname) ;First Name
$UserObj.Put("sn", $sname) ;Last Name(Surname)
$UserObj.Put("displayName", $accountname)
$UserObj.Put("description", $fname + " " + $sname) ;Description
$UserObj.Put("mail", "$accountname@@server.co.uk") ;E-mail
$UserObj.Put("wWWHomePage", "www.server.co.uk") ;Web page
$UserObj.Put("userPrincipalName", "$accountname@@student.server.co.uk") ;userPrincipalName
$UserObj.Put("scriptPath", "student.exe") ;Logon Script
$UserObj.Put("department", $group)
$UserObj.Put("title", $accountname)
$UserObj.Put("homeDrive", "H:")
$UserObj.Put("homeDirectory", "\\student.server.co.uk\home\" + $accountname)
$userObj.SetPassword($accountname) ;Sets the password to "newpassword"
$userObj.Put("pwdLastSet", 0) ;User has to change the pw as soon as he/she logs in
$userObj.AccountDisabled = 0 ;Enables the account
$UserObj.SetInfo
; Objects cleanup
$UserObj = 0
$OU = 0
EndFunction
$accountname = "studenttest"
$group = "studenttest"
$fname = "studenttest"
$sname = "studenttest"
$username = "studenttest"
$fullnamename = "studenttest"
CreateAccount("$accountname", "$accountname", "LDAP://student.server.co.uk/OU=Standard Policy,DC=student,DC=server,DC=co,DC=uk")