Active directory report
HI all,
I need a report where we can query an account name and see if this account has been created on any server/workstation and to which group has it been added i.e. administrator,
other etc..”
Can you people help me doing this. provide me steps to follow.Regards, Pratap
September 19th, 2011 12:51pm
This may be challanging. It is easy to query Active Directory using scripting such as Visual Basic, however, you would need to develop code that will interrogate each domain member to see if the account exists on that computer.
I would start by looking for code snippets at the MS Script Center:
http://technet.microsoft.com/en-us/scriptcenter
Visit anITKB.com, an IT Knowledge Base.
Free Windows Admin Tool Kit Click here and download it now
September 19th, 2011 1:24pm
If you are talking about a domain user (in Active Directory), you can query AD once. However, you talk about servers and workstations, which sounds like you mean a local account on one or more of the machines. If so, you must query every computer in the
domain (except Domain Controllers). But this is not an Active Directory report. You could query AD for all computers in the domain (except Domain Controllers), then connect remotely each in turn and search for a specified user name (if you have permissions).
Is this what you want?
Richard Mueller - MVP Directory Services
September 19th, 2011 1:31pm
Assuming you are looking for local user accounts, the following VBScript program works for me. However, it can take awhile, as it must connect to an object on each computer, and there is a timeout if the computer is not available.
Option Explicit
Dim objRootDSE, strDNSDomain, adoConnection, adoCommand, strQuery
Dim strFilter, strAttributes, adoRecordset, strComputer, strBase
Dim strUser, objUser, objGroup
' Prompt for local user to search for.
strUser = InputBox("Enter the name of the local user to find")
' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on all computers that are not DC's.
strFilter = "(&(objectCategory=computer)" _
& "(!userAccountControl:1.2.840.113556.1.4.803:=8192))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName"
' 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
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
strComputer = adoRecordset.Fields("sAMAccountName").Value
' Remove trailing "$" character.
strComputer = Left(strComputer, Len(strComputer) - 1)
' Check if specified local user exists on this computer.
' Trap error if the user does not exist.
On Error Resume Next
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user")
If (Err.Number = 0) Then
On Error GoTo 0
Wscript.Echo "User " & strUser & " exists on computer " & strComputer
' Enumerate direct group memberships.
For Each objGroup In objUser.Groups
Wscript.Echo " Member of group: " & objGroup.ADsPath
Next
Else
' User does not exist on this computer, or computer cannot be reached.
Select Case Err.Number
Case -2147024843
Wscript.Echo strComputer & " not found"
Case 70
Wscript.Echo strComputer & " permission denied"
Case -2147022675
Wscript.Echo strComputer & ", user not found"
Case Else
Wscript.Echo strComputer & " Error: " & Err.Number
Wscript.Echo " Description: " & Err.Description
End Select
On Error GoTo 0
End If
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Wscript.Echo "Done"
-----
You would run this script at a command prompt, using the cscript host program, so you can redirect the output to a text file. For example, if the script is saved in FindLocalUser.vbs, the command could be:
cscript //nologo FindLocalUser.vbs > FindUser.txt
Richard Mueller - MVP Directory Services
Free Windows Admin Tool Kit Click here and download it now
September 19th, 2011 2:03pm
If this does not help, consider posting here: http://social.technet.microsoft.com/Forums/en-US/ITCG/threads
This
posting is provided "AS IS" with no warranties or guarantees , and confers no rights.
Microsoft Student
Partner 2010 / 2011
Microsoft Certified Professional
Microsoft Certified Systems Administrator:
Security
Microsoft Certified Systems Engineer:
Security
Microsoft Certified Technology Specialist:
Windows Server 2008 Active Directory, Configuration
Microsoft Certified Technology Specialist:
Windows Server 2008 Network Infrastructure, Configuration
Microsoft Certified Technology Specialist:
Windows Server 2008 Applications Infrastructure, Configuration
Microsoft Certified Technology Specialist:
Windows 7, Configuring
Microsoft Certified IT Professional: Enterprise
Administrator
Microsoft Certified IT Professional: Server Administrator
September 19th, 2011 2:24pm


