bsharath
asked on
Find users who have the same contacts from ADS
We have many users and many contacts that we have the same.Is there a way a script can get only users and contacts that has the same names from the ADS.With the descriptions to a file.
Regards
Sharath
Regards
Sharath
ASKER
You are right but i just want to find users and contacts that have the same Fullname (Displayname)
Any way to get just the users that have contacts and user names the same.
Any way to get just the users that have contacts and user names the same.
Where are the users and contacts stored? Is it somewhere in a file or database or do they just login into the system and their id is on some global server.
What is ADS?
What is ADS?
ASKER
The users and contacts are stored in ADS (Active Directory)
Sharath, try this script:
'====================
If Right(LCase(WScript.FullNa me), 11) = "wscript.exe" Then
Set objShell = CreateObject("WScript.Shel l")
objShell.Run "cmd /k cscript """ & WScript.ScriptFullName & """", 1, False
Set objShell = Nothing
WScript.Quit
End If
Set adoCommand = CreateObject("ADODB.Comman d")
Set adoConnection = CreateObject("ADODB.Connec tion")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio n = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE" )
strDNSDomain = objRootDSE.Get("defaultNam ingContext ")
'strOUPath = "ou=users,ou=TestOU,"
strOUPath = ""
strBase = "<LDAP://" & strOUPath & strDNSDomain & ">"
strFilter = "(&(objectCategory=person) (objectCla ss=contact ))"
'(profilePath=" & strOldPath & "*)
'strFilter = "(&(objectClass=computer)( cn=" & strComputer & "))"
' Comma delimited list of attribute values to retrieve.
'strAttributes = "sAMAccountName,cn"
strAttributes = "displayName, distinguishedName"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Pag e Size") = 100
adoCommand.Properties("Tim eout") = 30
adoCommand.Properties("Cac he Results") = False
' Run the query for contacts
Set adoContactsRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoContactsRecordset.EOF
' Retrieve values and display.
strContactName = adoContactsRecordset.Field s("display Name").Val ue
strContactDN = adoContactsRecordset.Field s("disting uishedName ").Value
WScript.Echo "Checking Contact: " & strContactName & ": " & strContactDN
'Change and run the query for user accounts
strFilter = "(&(objectCategory=person) (objectCla ss=user)(d isplayName =" & strContactName & "))"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
Set adoUsersRecordset = adoCommand.Execute
Do Until adoUsersRecordset.EOF
strUserName = adoUsersRecordset.Fields(" displayNam e").Value
strUserDN = adoUsersRecordset.Fields(" distinguis hedName"). Value
If LCase(strContactName) = LCase(strUserName) Then
WScript.Echo
WScript.Echo ">>> " & "CONTACT " & strContactName & ": " & strContactDN
WScript.Echo ">>> " & "USER " & strUserName & ": " & strUserDN
WScript.Echo
End If
adoUsersRecordset.MoveNext
Loop
' Move to the next record in the recordset.
adoContactsRecordset.MoveN ext
Loop
' Clean up.
adoContactsRecordset.Close
Set adoContactsRecordset = Nothing
adoConnection.Close
WScript.Echo
WScript.Echo "Done"
MsgBox "Done"
'====================
Regards,
Rob.
'====================
If Right(LCase(WScript.FullNa
Set objShell = CreateObject("WScript.Shel
objShell.Run "cmd /k cscript """ & WScript.ScriptFullName & """", 1, False
Set objShell = Nothing
WScript.Quit
End If
Set adoCommand = CreateObject("ADODB.Comman
Set adoConnection = CreateObject("ADODB.Connec
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE"
strDNSDomain = objRootDSE.Get("defaultNam
'strOUPath = "ou=users,ou=TestOU,"
strOUPath = ""
strBase = "<LDAP://" & strOUPath & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)
'(profilePath=" & strOldPath & "*)
'strFilter = "(&(objectClass=computer)(
' Comma delimited list of attribute values to retrieve.
'strAttributes = "sAMAccountName,cn"
strAttributes = "displayName, distinguishedName"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Pag
adoCommand.Properties("Tim
adoCommand.Properties("Cac
' Run the query for contacts
Set adoContactsRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoContactsRecordset.EOF
' Retrieve values and display.
strContactName = adoContactsRecordset.Field
strContactDN = adoContactsRecordset.Field
WScript.Echo "Checking Contact: " & strContactName & ": " & strContactDN
'Change and run the query for user accounts
strFilter = "(&(objectCategory=person)
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
Set adoUsersRecordset = adoCommand.Execute
Do Until adoUsersRecordset.EOF
strUserName = adoUsersRecordset.Fields("
strUserDN = adoUsersRecordset.Fields("
If LCase(strContactName) = LCase(strUserName) Then
WScript.Echo
WScript.Echo ">>> " & "CONTACT " & strContactName & ": " & strContactDN
WScript.Echo ">>> " & "USER " & strUserName & ": " & strUserDN
WScript.Echo
End If
adoUsersRecordset.MoveNext
Loop
' Move to the next record in the recordset.
adoContactsRecordset.MoveN
Loop
' Clean up.
adoContactsRecordset.Close
Set adoContactsRecordset = Nothing
adoConnection.Close
WScript.Echo
WScript.Echo "Done"
MsgBox "Done"
'====================
Regards,
Rob.
ASKER
Thanks Rob this works perfect.
How does the script nmatch the contacts and NTlogins?
Can i get the output to a file.
How does the script nmatch the contacts and NTlogins?
Can i get the output to a file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent Rob....
1) You have many users
2) You have many contacts
3) Some of the users and contacts are the same
4) There is something called the ADS which presumably has some details about the users and contacts.
5) You want to get the users and contacts that have the same name, look them up in the ADS and dump them into a file.
Is that a fair analysis of what you're trying to achieve? If not, could you please explain what you really want.
Is ADS the Automated Deployment Service for Windows 2003 or is it something completely different?