1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
   | Option Explicit
 
DIM objConnection, objCommand, objRecordSet, objFSO, objF
DIM sOrdi, strPath, strName, strDescription, StrTmp
Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
strName="output.csv"
strPath=".\"
IF(objFSO.FileExists(strPath&strName)) Then
objFSO.DeleteFile strPath&strName
End if
SET objF=objFSO.CreateTextFile(strPath&strName)
objF.Close
Set objF=objFSO.openTextFile(strPath&strName,ForAppending)
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, Description from  'LDAP://OU=Stations,OU=site,DC=domaine' Where objectClass='computer'"
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
sOrdi = objRecordSet.Fields("Name").Value
 
strDescription = ""
If Not (IsNull(objRecordSet.Fields("Description").Value)) then
For each strTmp in objRecordSet.Fields("Description").Value
strDescription = strTmp
Next
End If
 
objF.WriteLine(sOrdi&";"&strDescription)
objRecordSet.MoveNext
Loop
objF.Close | 
Partager