Strony

wtorek, 11 października 2011

VBScript - skrypty AD

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

'SearchforaUserAccountinActiveDirectory

FilePath=".\samAccountName.txt"'Sciezkadoplikuzdanymiwejściowymi (np. JanKowalski)
SetobjFSO=CreateObject("Scripting.FileSystemObject")
SetobjFile=objFSO.OpenTextFile(FilePath,1)

DoUntilobjFile.AtEndOfStream
    strsamAccountName=objFile.ReadLine()

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

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

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


SetobjRecordSet=objCommand.Execute

IfobjRecordset.RecordCount=0Then
    'WScript.Echo"sAMAccountName:" & strsamAccountName & "doesnotexist."
Else  
    WhileNotobjRecordset.EOF
        SetobjUser=GetObject(objRecordset.Fields(0).Value)
        WScript.EchoobjRecordset.RecordCount & "|" & objUser.samAccountName & "|" & objUser.mail
        objRecordSet.MoveNext
    Wend
EndIf
objConnection.Close
Loop
[*] - usuń te znaki (Blogger filtruje publikowane treści)