LDAP Abfrage global
Dieses Script ist der gezielten LDAP-Abfrage sehr ähnlich.
Jedoch sucht es für jeden vorhandenen Service im Serververzeichnis die Zuordnung im AD heraus.
Was dabei herauskommt, ist für einen Audit evtl. ganz nützlich ...
'==========================================================================' Gobale Variable' LDAP Name des Objectes in dem gesucht wird'==========================================================================Const ForReading = 1, ForWriting = 2, ForAppending = 8strName = "*"
'==========================================================================' Ergebniss Datei'==========================================================================Set fs = CreateObject("Scripting.FileSystemObject")Set srcpath = fs.getfolder\\shvap022\d$\RADIADB\PRIMARY\SOFTWARE\ZSERVICE\")Set datei = fs.OpenTextfile("C:\test.txt",8,true)datei.WriteLine "name; class; adspath"
For Each i In srcpath.Filesdatei.WriteLine""datei.WriteLine""
dummy = Split(i, "\")test=UBound (dummy)'WScript.Echo test'wscript.echo dummystrSucheString = dummy(test)
datei.WriteLine strSucheString
'==========================================================================' Ask OU'==========================================================================strCategory = "organizationalUnit"'strSucheString = InputBox( "Radia suche", "Radia Pol suche")str1 = getItem(strName,strCategory,strSucheString)
'==========================================================================' Ask Group'==========================================================================strCategory = "group"'WScript.Echo "Gruppe: "str1 = getItem(strName,strCategory,strSucheString)
'==========================================================================' Ask Computer'=========================================================================='strCategory = "computer"'WScript.Echo "Computer: "'str1 = getItem(strName,strCategory,strSucheString)
next
'==========================================================================' Function'==========================================================================Function getItem(ItemNamen,ItemCategory,ItemInGroup)on error resume Next
Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _ "<LDAP://dc=intra,dc=ring-netz,dc=de>;" & _ "(&(objectCategory=" & ItemCategory & ")(name=" & ItemNamen & "));" & _ "ADsPath;subtree" Set objRecordSet = objCommand.Execute
objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 300 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst While Not objRecordSet.EOF strADsPath = objRecordSet.Fields("ADsPath") 'Zeigt dem LDAP Path an 'WScript.Echo strADsPath objRecordSet.MoveNext 'Auslesen der MultiBox strmemberOf = "" Item = "" Set objItem = GetObject(strADsPath) strmemberOf = objItem.GetEx("edmPolicy") For Each Item in strmemberOf strcheck = "0" strcheck = InStr( 1,Item,strSucheString,vbtextcompare) If strcheck > "0" Then  datei.WriteLine Item & "; " & ItemCategory & "; " & strADsPath End if Next WendEnd Function
'kopie=fs.copyfile (datei, "c:\audit_"&strSucheString&".txt")wscript.echo "LDAP-Abfrage hat Fertig!!!"