Question Locked

AD logon script querie

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I would like to creat a querie that would tell me what logon script each user has assigned to them in the AD. What would be the best tool to do this? I've tried using the saved queries, but can't seem to get the right info. I am running 2003 server.

Thank you

5 replies

by Member 25348569

to run an LDAP query to pull out all of the users. You can then step through the collection and list them out with whatever info you want.

Here's a user-extraction query that gets user name, Distinguished name and login script path

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Initiate ADO

Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

' Assemble query string

strBase = ""
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "distinguishedName,Name,ScriptPath"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' set parameters

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 60
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
wscript.echo objRecordSet.Fields("Name") & vbtab & objRecordSet.Fields("scriptPath")
objRecordSet.MoveNext
Loop

Have fun...

Neil :D

p.s. No, I won't debug it and I may well have made a slepling mistake! although if I spot any myself, I'll fix 'em.

by rob miners

you didn't make any slepling mistakes. Handy little script. Worked straight out of the box.

by Member 25348569

I just cut-and-pasted from my set of "scripts for all occasions" but I was trying to discourage additional questions from someone who I suspected might not know how to save and run it! I'm happy to help but spoon-feeding ain't my style.

That particular script is a mod of a standard script to list out absolutely anything for every user in AD. If you want to mod it, get the required Property Name from any LDAP browser (Softerra make a freebie) or Microsoft's ADSIEDIT and put it into the strAttributes variable (comma-separated values) and add to the final print-out line.

Neil :D

Disclaimer: All information is supplied without any guarantee that anything I ever type isn't a total lie and that any script that I post may completely trash your system.

Should this happen, please take time off from your job-hunting and peer-mail me in order that I - at least - can get a laugh out of it.

by rob miners

only new to scripting but I am slowly working on it. It has opened up a whole new world for me. I have used ADSIEDIT but only when I was making a script to add users. I cant write one from scratch but I have picked up enough info to be able to work them out. I used to add Users with a batch file. I modified one of Guy's scripts and now not only do I have User Accounts but Mail as well. I totally agree with you on the the spoon-feeding.

This discussion is closed to new replies.