LDAP-Synchronisation
This commit is contained in:
@@ -25,14 +25,9 @@ Public Class frmADsearch
|
||||
dt.Columns.Add("sAMAccountName", GetType(String))
|
||||
dt.Columns.Add("givenName", GetType(String))
|
||||
dt.Columns.Add("sn", GetType(String))
|
||||
dt.Columns.Add("DisplayName", GetType(String))
|
||||
dt.Columns.Add("distinguishedName", GetType(String))
|
||||
dt.Columns.Add("department", GetType(String))
|
||||
dt.Columns.Add("company", GetType(String))
|
||||
dt.Columns.Add("mail", GetType(String))
|
||||
dt.Columns.Add("cn", GetType(String))
|
||||
dt.Columns.Add("telephoneNumber", GetType(String))
|
||||
dt.Columns.Add("extensionAttribute7", GetType(String))
|
||||
dt.Columns.Add("adEntry", GetType(System.DirectoryServices.DirectoryEntry))
|
||||
|
||||
End Sub
|
||||
@@ -50,7 +45,6 @@ Public Class frmADsearch
|
||||
.Columns("GivenName").Width = 75
|
||||
.Columns("sn").Width = 100
|
||||
.Columns("sn").HeaderText = "Lastname"
|
||||
.Columns("DisplayName").Visible = False
|
||||
.Columns("sAMAccountName").Width = 75
|
||||
.Columns("sAMAccountName").HeaderText = "Account"
|
||||
.Columns("department").Width = 75
|
||||
@@ -59,9 +53,7 @@ Public Class frmADsearch
|
||||
.Columns("department").HeaderText = "Department"
|
||||
.Columns("company").Width = 75
|
||||
.Columns("company").HeaderText = "Company"
|
||||
.Columns("telephoneNumber").Visible = False
|
||||
.Columns("extensionAttribute7").Visible = False
|
||||
.Columns("cn").Visible = False
|
||||
.Columns("adEntry").Visible = False
|
||||
|
||||
End With
|
||||
|
||||
@@ -80,9 +72,8 @@ Public Class frmADsearch
|
||||
Try
|
||||
dirEntry = New System.DirectoryServices.DirectoryEntry(LDAPString)
|
||||
dirSearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)
|
||||
dirSearcher.Filter = "(samAccountName=" & username & ")"
|
||||
dirSearcher.PropertiesToLoad.Add("GivenName")
|
||||
dirSearcher.PropertiesToLoad.Add("sn")
|
||||
dirSearcher.Filter = " (&(objectClass=user)(objectCategory=person)(|(samAccountName=*" & username & "*)))"
|
||||
|
||||
Dim sr As DirectoryServices.SearchResultCollection = dirSearcher.FindAll()
|
||||
If sr Is Nothing Then
|
||||
lblHint.Text = "No Entries found"
|
||||
@@ -95,19 +86,13 @@ Public Class frmADsearch
|
||||
Dim de As System.DirectoryServices.DirectoryEntry
|
||||
de = srEntry.GetDirectoryEntry()
|
||||
|
||||
'Dim ObjFirstName As String = ""
|
||||
'Dim ObjLastName As String = String.Empty
|
||||
|
||||
Dim R As DataRow = dt.NewRow
|
||||
R("givenName") = de.Properties("givenName").Value.ToString()
|
||||
R("sAMAccountName") = de.Properties("sAMAccountName").Value.ToString()
|
||||
R("department") = de.Properties("department").Value.ToString()
|
||||
R("company") = de.Properties("company").Value.ToString()
|
||||
R("sn") = de.Properties("sn").Value.ToString()
|
||||
R("cn") = de.Properties("cn").Value.ToString()
|
||||
R("telephoneNumber") = de.Properties("telephoneNumber").Value.ToString()
|
||||
R("distinguishedName") = de.Properties("distinguishedName").Value.ToString()
|
||||
R("extensionAttribute7") = de.Properties("extensionAttribute7").Value.ToString()
|
||||
R("givenName") = setNoNullableValue(de.Properties("givenName").Value)
|
||||
R("sn") = setNoNullableValue(de.Properties("sn").Value)
|
||||
R("sAMAccountName") = setNoNullableValue(de.Properties("sAMAccountName").Value)
|
||||
R("department") = setNoNullableValue(de.Properties("department").Value)
|
||||
R("distinguishedName") = setNoNullableValue(de.Properties("distinguishedName").Value)
|
||||
R("company") = setNoNullableValue(de.Properties("company").Value)
|
||||
R("adEntry") = de
|
||||
dt.Rows.Add(R)
|
||||
|
||||
@@ -162,23 +147,30 @@ Public Class frmADsearch
|
||||
|
||||
For Each row As DataGridViewRow In dgvAD.SelectedRows
|
||||
activeDirectoryObj = New ADObject With {
|
||||
.sn = IIf(IsDBNull(row.Cells("sn").Value), "", row.Cells("sn").Value),
|
||||
.sAMAccountName = IIf(IsDBNull(row.Cells("sAMAccountName").Value), "", row.Cells("sAMAccountName").Value),
|
||||
.givenName = IIf(IsDBNull(row.Cells("givenName").Value), "", row.Cells("givenName").Value),
|
||||
.cn = IIf(IsDBNull(row.Cells("cn").Value), "", row.Cells("cn").Value),
|
||||
.department = IIf(IsDBNull(row.Cells("department").Value), "", row.Cells("department").Value),
|
||||
.company = IIf(IsDBNull(row.Cells("company").Value), "", row.Cells("company").Value),
|
||||
.telephoneNumber = IIf(IsDBNull(row.Cells("telephoneNumber").Value), "", row.Cells("telephoneNumber").Value),
|
||||
.distinguishedName = IIf(IsDBNull(row.Cells("distinguishedName").Value), "", row.Cells("distinguishedName").Value),
|
||||
.mail = IIf(IsDBNull(row.Cells("mail").Value), "", row.Cells("mail").Value),
|
||||
.domain = cboDomain.Text,
|
||||
.emailExtension = IIf(IsDBNull(row.Cells("extensionAttribute7").Value), "", row.Cells("extensionAttribute7").Value),
|
||||
.ADEntry = IIf(IsDBNull(row.Cells("adEntry").Value), "", row.Cells("adEntry").Value)
|
||||
}
|
||||
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function setNoNullableValue(value As String) As String
|
||||
|
||||
If value IsNot Nothing Then
|
||||
If value <> "" Then
|
||||
Return value
|
||||
End If
|
||||
End If
|
||||
Return ""
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub txtUser_KeyDown(sender As Object, e As KeyEventArgs) Handles txtUser.KeyDown
|
||||
If e.KeyCode = Keys.Enter Then
|
||||
btnSearch_Click(sender, e)
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class ADObject
|
||||
@@ -186,17 +178,7 @@ Public Class ADObject
|
||||
Public Sub New()
|
||||
End Sub
|
||||
|
||||
Public Property sn As String
|
||||
Public Property givenName As String
|
||||
Public Property cn As String
|
||||
Public Property department As String
|
||||
Public Property company As String
|
||||
Public Property telephoneNumber As String
|
||||
Public Property distinguishedName As String
|
||||
Public Property mail As String
|
||||
Public Property sAMAccountName As String
|
||||
Public Property domain As String
|
||||
Public Property emailExtension As String
|
||||
Public Property ADEntry As System.DirectoryServices.DirectoryEntry
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user