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
| Option Explicit
DIM objConnection, objCommand, objRecordSet, objFSO, objF
DIM sOrdi, strPath, strName, descript
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, Location, DistinguishedName 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
descript = objRecordSet.Fields("Description").Value
objF.WriteLine(sOrdi&";"&descript)
objRecordSet.MoveNext
Loop
objF.Close |
Partager