我目前正在编写一个小应用来更新AD字段而不使用Windows工具 除非您按下"更新"
,否则它会很有效LDAP提交会返回错误,我不知道哪一个
If (sn.Text <> "" And givenname.Text <> "" And employeeId.Text <> "") Then
If Int32.TryParse(employeeId.Text, id) Then
Dim infos As DirectoryEntry = New DirectoryEntry("LDAP://ad.mairie-blagnac.fr/<GUID=" + user_guid + ">")
infos.Properties("sn").Value = sn.Text
infos.Properties("givenname").Value = givenname.Text
infos.Properties("displayName").Value = sn.Text + " " + givenname.Text
infos.Properties("employeeId").Value = employeeId.Text
infos.Properties("physicaldeliveryofficename").Value = physicaldeliveryofficename.Text
infos.Properties("company").Value = company.Text
infos.Properties("department").Value = department.Text
infos.Properties("title").Value = title.Text
infos.Properties("employeeNumber").Value = employeeNumber.SelectedValue
infos.Properties("employeeType").Value = employeeType.SelectedValue
infos.Properties("streetAddress").Value = streetAddress.Text
infos.Properties("homephone").Value = homephone.Text
infos.Properties("telephoneNumber").Value = telephoneNumber.Text
infos.Properties("pager").Value = pager.Text
infos.CommitChanges()
Else
MsgBox("Wrong employee ID")
End If
Else
MsgBox("Name, last name and employee ID are required")
End If
并非所有字段都已设置(空) 我有权更新AD用户,因为我是域管理员。
你们有什么想法吗?
答案 0 :(得分:0)
实测值。
我有3个必填字段
infos.Properties("sn").Value = sn.Text
infos.Properties("givenname").Value = givenname.Text
infos.Properties("employeeId").Value = employeeId.Text
其他字段为空,LDAP不接受
最终代码
If (sn.Text <> "" And givenname.Text <> "" And employeeId.Text <> "") Then
If Int32.TryParse(employeeId.Text, id) Then
Dim infos As DirectoryEntry = New DirectoryEntry("LDAP://ad.mairie-blagnac.fr/<GUID=" + user_guid + ">")
infos.Properties("sn").Value = sn.Text
infos.Properties("givenname").Value = givenname.Text
infos.Properties("displayName").Value = sn.Text + " " + givenname.Text
infos.Properties("employeeId").Value = employeeId.Text
If physicaldeliveryofficename.TextLength > 0 Then
infos.Properties("physicaldeliveryofficename").Value = physicaldeliveryofficename.Text
End If
If company.TextLength > 0 Then
infos.Properties("company").Value = company.Text
End If
If department.TextLength > 0 Then
infos.Properties("department").Value = department.Text
End If
If title.TextLength > 0 Then
infos.Properties("title").Value = title.Text
End If
If employeeNumber.SelectedValue <> "" Then
infos.Properties("employeeNumber").Value = employeeNumber.SelectedValue
End If
If employeeType.SelectedValue <> "" Then
infos.Properties("employeeType").Value = employeeType.SelectedValue
End If
If streetAddress.TextLength > 0 Then
infos.Properties("streetAddress").Value = streetAddress.Text
End If
If homephone.TextLength > 0 Then
infos.Properties("homephone").Value = homephone.Text
End If
If telephoneNumber.TextLength > 0 Then
infos.Properties("telephoneNumber").Value = telephoneNumber.Text
End If
If pager.TextLength > 0 Then
infos.Properties("pager").Value = pager.Text
End If
infos.CommitChanges()
confirm.Text = "User updated"
For Each item As ListViewItem In list_users.Items
If item.SubItems(0).Text = varDN Then
item.SubItems(0).Text = sn.Text + " " + givenname.Text
item.SubItems(1).Text = employeeId.Text
item.SubItems(2).Text = title.Text
item.SubItems(3).Text = department.Text
End If
Next
Else
MsgBox("Wrong employee ID")
End If
Else
MsgBox("Name, last name and employee ID are required")
End If
如果你有任何优化我会接受它
由于