Strony

wtorek, 11 października 2011

VBScript - skrypty AD

1. Wyszukiwanie użytkownika w AD i listowanie jego atrybutów.

' Search for a User Account in Active Directory

FilePath= ".\samAccountName.txt" ' Sciezka do pliku z danymi wejściowymi (np. JanKowalski)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FilePath, 1)

Do Until objFile.AtEndOfStream
    strsamAccountName = objFile.ReadLine()

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<[*]LDAP://dc=domain,dc=com,dc=pl>;(&(objectCategory=User)" & _
"(samAccountName=" & strsamAccountName & "));adspath;subtree"


Set objRecordSet = objCommand.Execute

If objRecordset.RecordCount = 0 Then
    'WScript.Echo "sAMAccountName: " & strsamAccountName & " does not exist."
Else  
    While Not objRecordset.EOF
        Set objUser = GetObject (objRecordset.Fields(0).Value)
        WScript.Echo objRecordset.RecordCount & "|" & objUser.samAccountName & "|" & objUser.mail
        objRecordSet.MoveNext
    Wend
End If
objConnection.Close
Loop
[*] - usuń te znaki (Blogger filtruje publikowane treści)