Updated code.
A problem was pointed out to me. The lines:
Code:
$aDom = split($Domain,".")
$sDNdom = ",dc=" + $aDom[0] + ",dc=" + $aDom[1] + ",dc=" + $aDom[2]
will fail if the text for the first paramater ($Domain) does not contain two periods. The following code is more tolerance and will work with if there are any number of periods, including zero, in the domain name.
Code:
CreateUserAccount("my.domain.com",
"cn=Users",
"BullockTest",
"Howard",
"A",
"Bullock",
"Super Admin",
"Corner with a view",
"999-555-1212",
"habullock@@comcast.net",
"http://home.comcast.net/~habullock" )
Function CreateUserAccount($Domain,
$ContainerDN,
$Account,
optional $FirstName,
optional $MiddleInitial,
optional $LastName,
optional $Description,
optional $Office,
optional $Telephone,
optional $Email,
optional $WebPage,
optional $userPrincipalName )
Dim $aDom, $part, $sDNdom, $LDAPpath, $oContainer, $oUser
if VarTypeName($userPrincipalName) = "Empty"
$userPrincipalName = $Account + "@@" + $Domain
endif
$aDom = split($Domain,".")
for each $part in $aDom
$sDNdom = "" + $sDNdom + ",dc=" + $part
next
$LDAPpath = "LDAP://" + $Domain + "/" + $ContainerDN + $sDNdom
;? $LDAPpath
$oContainer = GetObject($LDAPpath)
if @error
? "GetObject Error: " + @error + " " + @Serror
endif
$oUser = $oContainer.Create("User", "cn=" + $Account)
if @error
? "Create Error: " + @error + " " + @Serror
endif
$oUser.Put("sAMAccountName", $Account)
$oUser.Put("givenName", $FirstName) ;First Name
$oUser.Put("Initials", $MiddleInitial) ;Initials
$oUser.Put("sn", $LastName) ;Last Name(Surname)
$oUser.Put("displayName",$LastName + iif($LastName, ", ","") +
$FirstName + iif($MiddleInitial, " ", "") +
$MiddleInitial) ;Display name
$oUser.Put("description", $Description) ;Description
$oUser.Put("physicalDeliveryOfficeName",$Office) ;Office
$oUser.Put("telephoneNumber",$Telephone);Telephone
$oUser.Put("mail",$Email) ;E-mail
$oUser.Put("wWWHomePage",$WebPage) ;Web page
$oUser.Put("userPrincipalName", $userPrincipalName) ;userPrincipalName
$oUser.SetInfo
$CreateUserAccount = @error
if $CreateUserAccount
? "SetInfo Error: " + @error + " " + @Serror
endif
Endfunction