我正在创建一个用于创建AD帐户的程序,但是当我创建一个用户时,它不会加入到AD域中,它会阻止我关联这个新帐户的电子邮件地址。
我的广告用户错误排版:http://nsa37.casimages.com/img/2015/10/23/151023115708482493.jpg
有谁知道如何或可以帮助我解决这个问题?
感谢帮助我, 最好的问候,
Private Sub CreateADUserAccount(ByVal ldapPath As String, ByVal username As String, ByVal username2 As String, ByVal userPassword As String, ByVal admusername As String, ByVal admpw As String, ByVal addomainee As String) As Boolean
Try
Dim entry As New DirectoryEntry(ldapPath, admusername, admpw, AuthenticationTypes.Secure)
'Création de l'Unité d'Organisation
Dim entry1 As DirectoryEntry = entry.Children.Add(("OU=Private Administrators"), "organizationalUnit")
Dim Verifu1 As Boolean = True
entry1.CommitChanges()
'Raccourci de connexion à l'Unité d'Organisation
Dim OUentry As DirectoryEntry = entry.Children.Find("OU=Private Administrators")
'Create first user
Dim entry2 As DirectoryEntry = OUentry.Children.Add(("CN=" & username), "user")
entry2.Properties.Item("samAccountName").Value = (username)
entry2.Properties.Item("displayName").Value = username
entry2.Properties.Item("userPrincipalName").Value = username
entry2.CommitChanges()
Dim entrySearch As DirectorySearcher = New DirectorySearcher(entry)
entrySearch.Filter = "(&(objectClass=user)(SAMAccountName=" & username & "))"
Dim OneSearchResult As SearchResult = entrySearch.FindOne
Dim AlterUser As DirectoryEntry = OneSearchResult.GetDirectoryEntry()
AlterUser.AuthenticationType = AuthenticationTypes.Secure
AlterUser.Invoke("SetPassword", userPassword)
AlterUser.CommitChanges()
'Active Account & Password never expire
AlterUser.Properties.Item("userAccountControl").Value = (66048)
AlterUser.CommitChanges()
'User doesnt need to change password after first login
AlterUser.Properties("PwdLastSet").Value = 0
AlterUser.CommitChanges()
AlterUser.Close()
End Sub
答案 0 :(得分:0)
Finnaly我通过编辑这一行来解决我的问题:
entry2.Properties.Item("UserPrincipalName").Value = username
要
Dim fulldomain As String = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties.DomainName.ToString
entry2.Properties.Item("UserPrincipalName").Value = username & "@" & fulldomain