Active Directory Data

Dear Admins,

I have a list of users generated from SMS inventory. I have all the GUID's present but many AD user id's are missing. I want to get the list of all the user id's with the help of GUID's. Please help me with an automated script. Manually finding is not possible because more than 60000 users are present.

Kindly request you to help me out on this.

Thanks in Advance.

--Venkat
LVL 3
venkatspbSenior Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sushil SonawaneCommented:
You can achieve these through AD manager plus. It is tool for 30 days trail version.

For more info and download refer below link:
http://www.manageengine.com/products/ad-manager/
0
RobSampsonCommented:
Have you tried using Active Directory Users and Computers to create a custom query that pulls the objectGUID attribute, and the samAccountName attribute?  You could export this to CSV then filter it as you need to.

Regards,

Rob.
0
Rich RumbleSecurity SamuraiCommented:
Use CSVDE or LDIFDE to export all of AD to a csv.
csvde.exe -s dc_server.comapny.com -f c:\temp\ad-output.csv
that will dump all of dc_server to ad_output.csv
you can specify other domain controllers and even use alternate credentials if you need.
-rich
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

RobSampsonCommented:
Can you confirm what the attribute is called that you want to seach by?  In ADU&C, view the properties of a user account, then click the Attribute Editor tab.  Scroll down the list until you see the value you have, and let us know what that attribute is called.

Regards,

Rob.
0
venkatspbSenior Software EngineerAuthor Commented:
Adsiedit Screenshot
Attached the screenshot of the attribute that I am looking for is ObjectGUID.

1. I have GUID's and I want all the user id's
2. I have user ids and I require the Guid's.

This is required because we are doing winxp to win7 migrations.

Please help me.

Thanks
Venkat
0
RobSampsonCommented:
This script will read the GUID strings from a text file, and output the usernames of each into a CSV file.

strInput = "GUIDs.txt"
strOutput = "GUID_Usernames.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """GUID"",""Username"""
While Not objInput.AtEndOfStream
	strLine = Trim(objInput.ReadLine)
	If strLine <> "" Then
		On Error Resume Next
		Set objUser = GetObject("LDAP://<GUID=" & strLine & ">")
		If Err.Number = 0 Then
			objOutput.WriteLine """" & objUser.GUID & """,""" & objUser.samAccountName & """"
		Else
			objOutput.WriteLine """" & objUser.GUID & """,""<NOT FOUND>"""
		End If
		Err.Clear
		On Error GoTo 0
	End If
Wend
objInput.Close
objOutput.Close
WScript.Echo "Done"

Open in new window

0
RobSampsonCommented:
This code should read users.txt and return the GUIDs to a CSV.

Regards,

Rob.

strInput = "users.txt"
strOutput = "Usernames_GUIDs.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """GUID"",""Username"""
While Not objInput.AtEndOfStream
	strLine = Trim(objInput.ReadLine)
	If strLine <> "" Then
		strUserADsPath = Get_LDAP_User_Properties("user", "samAccountName", strLine, "adsPath")
		If strUserADsPath <> "" Then
			Set objUser = GetObject(strUserADsPath)
			objOutput.WriteLine """" & objUser.guid & """,""" & strLine & """"
		Else
			objOutput.WriteLine """<NOT FOUND>"",""" & strLine & """"
		End If
	End If
Wend
objInput.Close
objOutput.Close
WScript.Echo "Done"

Function Get_LDAP_User_Properties(strObjectType, strSearchField, strObjectToGet, strCommaDelimProps)
      
      ' This is a custom function that connects to the Active Directory, and returns the specific
      ' Active Directory attribute value, of a specific Object.
      ' strObjectType: usually "User" or "Computer"
      ' strSearchField: the field by which to seach the AD by. This acts like an SQL Query's WHERE clause.
      '             It filters the results by the value of strObjectToGet
      ' strObjectToGet: the value by which the results are filtered by, according the strSearchField.
      '             For example, if you are searching based on the user account name, strSearchField
      '             would be "samAccountName", and strObjectToGet would be that speicific account name,
      '             such as "jsmith".  This equates to "WHERE 'samAccountName' = 'jsmith'"
      ' strCommaDelimProps: the field from the object to actually return.  For example, if you wanted
      '             the home folder path, as defined by the AD, for a specific user, this would be
      '             "homeDirectory".  If you want to return the ADsPath so that you can bind to that
      '             user and get your own parameters from them, then use "ADsPath" as a return string,
      '             then bind to the user: Set objUser = GetObject("LDAP://" & strReturnADsPath)
      
      ' Now we're checking if the user account passed may have a domain already specified,
      ' in which case we connect to that domain in AD, instead of the default one.
      If InStr(strObjectToGet, "\") > 0 Then
            arrGroupBits = Split(strObjectToGet, "\")
            strDC = arrGroupBits(0)
            strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")
            strObjectToGet = arrGroupBits(1)
      Else
      ' Otherwise we just connect to the default domain
            Set objRootDSE = GetObject("LDAP://RootDSE")
            strDNSDomain = objRootDSE.Get("defaultNamingContext")
      End If
 
      strBase = "<LDAP://" & strDNSDomain & ">"
      ' Setup ADO objects.
      Set adoCommand = CreateObject("ADODB.Command")
      Set ADOConnection = CreateObject("ADODB.Connection")
      ADOConnection.Provider = "ADsDSOObject"
      ADOConnection.Open "Active Directory Provider"
      adoCommand.ActiveConnection = ADOConnection
 
 
      ' Filter on user objects.
      'strFilter = "(&(objectCategory=person)(objectClass=user))"
      strFilter = "(&(objectClass=" & strObjectType & ")(" & strSearchField & "=" & strObjectToGet & "))"
 
      ' Comma delimited list of attribute values to retrieve.
      strAttributes = strCommaDelimProps
      arrProperties = Split(strCommaDelimProps, ",")
 
      ' Construct the LDAP syntax query.
      strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
      adoCommand.CommandText = strQuery
      ' Define the maximum records to return
      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.
      strReturnVal = ""
      Do Until adoRecordset.EOF
          ' Retrieve values and display.
          For intCount = LBound(arrProperties) To UBound(arrProperties)
                If strReturnVal = "" Then
                      strReturnVal = adoRecordset.Fields(intCount).Value
                Else
                      strReturnVal = strReturnVal & vbCrLf & adoRecordset.Fields(intCount).Value
                End If
          Next
          ' Move to the next record in the recordset.
          adoRecordset.MoveNext
      Loop
 
      ' Clean up.
      adoRecordset.Close
      ADOConnection.Close
      Get_LDAP_User_Properties = strReturnVal
 
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
venkatspbSenior Software EngineerAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.