amnhtech
asked on
Querying AD for Department membership for 1500 user script
I have a file with names / First , Last / and I need to get everybodys department from AD. What the easiest way to automate this?
ASKER
actually my goal here is to input names from a file and find out their department membership
Sorry i dont know of a way as such.You can still get all data put in excel sort the data and match with your list...
May be some other expert may help with this post...
May be some other expert may help with this post...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you very much for the script it looks like there is a small problem taht i can't figure out. Here is the errors i am getting
Querying: John Smith
dsquery failed:No superior reference has been configured for the directory servi
ce. The directory service is therefore unable to issue referrals to objects outs
ide this forest.
Please advise
Querying: John Smith
dsquery failed:No superior reference has been configured for the directory servi
ce. The directory service is therefore unable to issue referrals to objects outs
ide this forest.
Please advise
On what OS you are running this script?
Can please run following commands (one by one) and post the results?
Click Start -> Run -> Cmd.exe
DSQuery * -Filter "(&(samAccountType=8053063 68)(givenN ame=John)( sn=Smith)) "
DSQuery * DomainRoot -Filter "(&(samAccountType=8053063 68)(givenN ame=John)( sn=Smith)) "
DSQuery * ForestRoot -Filter "(&(samAccountType=8053063 68)(givenN ame=John)( sn=Smith)) "
DSQuery user -name John*
DSQuery user DomainRoot -name *
DSQuery user ForestRoot -name *
Can please run following commands (one by one) and post the results?
Click Start -> Run -> Cmd.exe
DSQuery * -Filter "(&(samAccountType=8053063
DSQuery * DomainRoot -Filter "(&(samAccountType=8053063
DSQuery * ForestRoot -Filter "(&(samAccountType=8053063
DSQuery user -name John*
DSQuery user DomainRoot -name *
DSQuery user ForestRoot -name *
ASKER
acctually i figured out i had a problem with cvs file there were a space infront the names. Thank you very much.
Great! Thanks for the points.
Save this file as vbs and run
You will get all users from the ad with department.
I got this from one of the posts in EE.
Option Explicit
Const ADS_SCOPE_SUBTREE = 2
Dim objConnection, objCommand, objRecordSet, objRootDSE, objFileSystem, objFile, objUser
Dim strDisplayName, strDepartment, strUserName
Set objConnection = CreateObject("ADODB.Connec
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Comman
objCommand.ActiveConnectio
Set objRootDSE = GetObject("LDAP://RootDSE"
objCommand.CommandText = "SELECT aDSPath, displayName, sAMAccountName, department FROM " &_
"'LDAP://" & objRootDSE.Get("defaultNam
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Sea
objCommand.Properties("Cac
Set objRecordSet = objCommand.Execute
Set objRootDSE = Nothing
Set objFileSystem = CreateObject("Scripting.Fi
Set objFile = objFileSystem.OpenTextFile
While Not objRecordSet.EOF
Set objUser = GetObject(objRecordSet.Fie
If objUser.Class = "user" Then
strDisplayName = ""
If Not IsNull(objRecordSet.Fields
strDisplayName = objRecordSet.Fields("displ
End If
strDepartment = ""
If Not IsNull(objRecordSet.Fields
strDepartment = objRecordSet.Fields("depar
End If
strUserName = objRecordSet.Fields("sAMAc
objFile.WriteLine strDisplayName & VbTab & strUserName & VbTab & strDepartment
End If
objRecordSet.MoveNext
Wend
objConnection.Close
Set objFile = Nothing
Set objFileSystem = Nothing
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing