Vestax 10 Geschrieben 22. August 2011 Melden Geschrieben 22. August 2011 Hallo, gibt es per WSH eine Möglichkeit leere OUs einer Domäne herauszusuchen? Ich habe dieses Script dazu gefunden: Option Explicit Dim adoCommand, adoConnection, strBase, strFilter, strAttributes Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strADsPath Dim objOU, lngCount, objChild ' Setup ADO objects. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoCommand.ActiveConnection = adoConnection ' Search entire Active Directory domain. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") strBase = "<LDAP://" & strDNSDomain & ">" ' Filter on all OU objects. strFilter = "(objectCategory=organizationalUnit)" ' Comma delimited list of attribute values to retrieve. strAttributes = "ADsPath" ' Construct the LDAP syntax query. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False ' Run the query. Set adoRecordset = adoCommand.Execute ' Enumerate the resulting recordset. Wscript.Echo "Empty organizational Units:" Do Until adoRecordset.EOF ' Retrieve values. strADsPath = adoRecordset.Fields("ADsPath").Value ' Bind to the OU object. Set objOU = GetObject(strADsPath) ' Check if empty. lngCount = 0 For Each objChild In objOU lngCount = lngCount + 1 Exit For Next If (lngCount = 0) Then Wscript.Echo objOU.distinguishedName End If ' Move to the next record in the recordset. adoRecordset.MoveNext Loop ' Clean up. adoRecordset.Close adoConnection.Close An sich funktioniert das schon ganz gut. Es wäre genial, wenn dann nur die erste (Parent-)OU ausgegeben wird, wenn sich mehrere leere OUs unterhalb davon befinden. Kann mir da einer weiterhelfen? Vielen Dank! :)
NilsK 3.052 Geschrieben 23. August 2011 Melden Geschrieben 23. August 2011 Moin, bitte beim Posten fremder Inhalte immer die Quelle mit angeben. Erstens gebietet das der Respekt, zweitens haben wir nur so eine sinnvolle Möglichkeit, dem Sinn des Geposteten nachzugehen. Was ist genau das Ziel, das du erreichen willst? Wozu benötigst du die Auflistung? Gruß, Nils
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden