Imports System.DirectoryServices
Imports System.Text
Imports System.IO
Module Module1
Sub Main()
Dim Subjects As String = String.Empty
Dim path_to_export As String = "\\server\share\"
Dim listOfProps As New List(Of String)
listOfProps.Add("displayName")
listOfProps.Add("mail")
listOfProps.Add("department")
listOfProps.Add("title")
listOfProps.Add("telephoneNumber")
listOfProps.Add("otherTelephone")
listOfProps.Add("msExchHideFromAddressLists")
listOfProps.Add("l")
listOfProps.Add("co")
For Each o In listOfProps
Subjects &= o & ";"
Next
Subjects &= vbCrLf
Dim Searcher As New DirectorySearcher()
Searcher.PageSize = 10000
Searcher.SizeLimit = 10000
Searcher.Filter = "(&(mail=*)(title=*)(Department=*))"
Dim temp_row As String
For Each sr In Searcher.FindAll()
For Each l In listOfProps
temp_row = String.Empty
Try
For Each prop In sr.properties(l)
If temp_row = String.Empty Then
temp_row &= prop.ToString
Else
temp_row &= " , " & prop.ToString
End If
Next
Subjects &= temp_row & ";"
Catch
Subjects &= "-;"
End Try
Next
Subjects &= vbCrLf
Next
Dim CSV As New StreamWriter(path_to_export & Today & "e.csv", False, Encoding.GetEncoding("Windows-1251"))
CSV.Write(Subjects)
CSV.Close()
End Sub
End Module
Imports System.Text
Imports System.IO
Module Module1
Sub Main()
Dim Subjects As String = String.Empty
Dim path_to_export As String = "\\server\share\"
Dim listOfProps As New List(Of String)
listOfProps.Add("displayName")
listOfProps.Add("mail")
listOfProps.Add("department")
listOfProps.Add("title")
listOfProps.Add("telephoneNumber")
listOfProps.Add("otherTelephone")
listOfProps.Add("msExchHideFromAddressLists")
listOfProps.Add("l")
listOfProps.Add("co")
For Each o In listOfProps
Subjects &= o & ";"
Next
Subjects &= vbCrLf
Dim Searcher As New DirectorySearcher()
Searcher.PageSize = 10000
Searcher.SizeLimit = 10000
Searcher.Filter = "(&(mail=*)(title=*)(Department=*))"
Dim temp_row As String
For Each sr In Searcher.FindAll()
For Each l In listOfProps
temp_row = String.Empty
Try
For Each prop In sr.properties(l)
If temp_row = String.Empty Then
temp_row &= prop.ToString
Else
temp_row &= " , " & prop.ToString
End If
Next
Subjects &= temp_row & ";"
Catch
Subjects &= "-;"
End Try
Next
Subjects &= vbCrLf
Next
Dim CSV As New StreamWriter(path_to_export & Today & "e.csv", False, Encoding.GetEncoding("Windows-1251"))
CSV.Write(Subjects)
CSV.Close()
End Sub
End Module
Комментариев нет:
Отправить комментарий