где-то так (VBS):
Код:
strLoginName = "IvanBB"
strFirstName = "Иван"
strLastName = "Иванов"
strRDName = strLastName & " " & strFirstName ' Имя объекта в AD
strPassword = "Password#14576"
strUserOU = "ou=OU1"
strGroup = "cn=Group1,ou=groups"
strHomeRoot = "\\SERVER\HOME"
Set objRoot = GetObject("LDAP://RootDSE")
Set objADSystemInfo = CreateObject("ADSystemInfo")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDomainDNSName = objADSystemInfo.DomainDNSName
strDomainDN = objRoot.Get("DefaultNamingContext")
strContainerDN = strUserOU & "," & strDomainDN
strGroupDN = strGroup & "," & strDomainDN
strUserDN = "cn=" & strLoginName & "," & strContainerDN
strHomeDirPath = strHomeRoot & "\" & strLastName & " " & strFirstName
Set objContainer = GetObject("LDAP://" & strContainerDN)
Set objUser = objContainer.Create("user","cn=" & strLoginName)
Set objGroup = GetObject("LDAP://" & strGroupDN)
objUser.Put "sAMAccountName", strLoginName
objUser.Put "userPrincipalName", strLoginName & "@" & strDomainDNSName
objUser.Put "givenName", strFirstName
objUser.Put "sn", strLastName
objUser.Put "displayName", strLastName & " " & strFirstName
objUser.Put "HomeDirectory", strHomeDirPath
objUser.Setinfo
objUser.SetPassword strPassword
objUser.AccountDisabled = FALSE
objUser.Setinfo
objGroup.Add("LDAP://" & strUserDN)
objGroup.Setinfo
objContainer.MoveHere "LDAP://" & strUserDN, "cn=" & strRDName
objContainer.Setinfo
If Not objFSO.FolderExists(strHomeDirPath) Then objFSO.CreateFolder(strHomeDirPath)