;This code copies the attributes in the Attrs array from an
;existing object to a new one.
;------ SCRIPT CONFIGURATION ------
$arrAttrs = "department", "co", "title", "l", "c", "st"
$strParentDN = "<ParentContainer>" ;e.g. cn=Users,dc=rallencorp,dc=com
$strTemplateUser = "<TemplateUserName>" ;e.g. template-user-sales
$strNewUser = "<NewUserName>" ;e.g. jdoe
$strPassword = "<Password>"
;------ END CONFIGURATION ---------
$ADS_UF_NORMAL_ACCOUNT = 512 ;from ADS_USER_FLAG_ENUM
$objTemplate = GetObject( "LDAP://cn=" + $strTemplateUser + "," + $strParentDN )
$objParent = GetObject("LDAP://" + $strParentDN)
$objUser = $objParent.Create("user", "cn=" + $strNewUser)
$objUser.Put "sAMAccountName", $strNewUser
For Each $strAttr in $arrAttrs
$objUser.Put $strAttr, $objTemplate.Get($strAttr)
Next
$objUser.SetInfo
$objUser.SetPassword($strPassword)
$objUser.SetInfo
$objUser.Put "userAccountControl", $ADS_UF_NORMAL_ACCOUNT
$objUser.AccountDisabled = FALSE
$objUser.SetInfo
? "Successfully created user"