Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Dumping logon name and logon script values to a text file - blank logon script field

Reply
Thread Tools Display Modes

Dumping logon name and logon script values to a text file - blank logon script field

 
 
Phil McNeill
Guest
Posts: n/a

 
      08-13-2008
A while back someone here was kind enough to provide me with the following
script and advice on how to dump these two values to a text file. It worked
great except for one thing. If the user had no logon script, they were
ignored by the script and didn't appear at all in the output. I am hoping
someone can tell me what I'd need to modify in the script below to dump a
list of the AD users with blank Logon Script values.

Thanks!



"Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes

Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strScript



' Setup ADO objects.

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



' Search entire Active Directory domain.

Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"


' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"



' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,scriptPath"



' 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



' Run the query.
Set adoRecordset = adoCommand.Execute


' Enumerate the resulting recordset.
Do Until adoRecordset.EOF

' Retrieve values and display.
strName = adoRecordset.Fields("sAMAccountName").Value

strScript = adoRecordset.Fields("scriptPath").value

Wscript.Echo strName & "," & strScript

' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop



' Clean up.

adoRecordset.Close

adoConnection.Close

===========


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      08-13-2008
Phil McNeill wrote:

>A while back someone here was kind enough to provide me with the following
>script and advice on how to dump these two values to a text file. It
>worked great except for one thing. If the user had no logon script, they
>were ignored by the script and didn't appear at all in the output. I am
>hoping someone can tell me what I'd need to modify in the script below to
>dump a list of the AD users with blank Logon Script values.
>
> Thanks!
>
>
>
> "Option Explicit
>
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
>
> Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strScript
>
>
>
> ' Setup ADO objects.
>
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> adoCommand.ActiveConnection = adoConnection
>
>
>
> ' Search entire Active Directory domain.
>
> Set objRootDSE = GetObject("LDAP://RootDSE")
>
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
> strBase = "<LDAP://" & strDNSDomain & ">"
>
>
> ' Filter on user objects.
> strFilter = "(&(objectCategory=person)(objectClass=user))"
>
>
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "sAMAccountName,scriptPath"
>
>
>
> ' 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
>
>
>
> ' Run the query.
> Set adoRecordset = adoCommand.Execute
>
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
>
> ' Retrieve values and display.
> strName = adoRecordset.Fields("sAMAccountName").Value
>
> strScript = adoRecordset.Fields("scriptPath").value
>
> Wscript.Echo strName & "," & strScript
>
> ' Move to the next record in the recordset.
> adoRecordset.MoveNext
> Loop
>
>
>
> ' Clean up.
>
> adoRecordset.Close
>
> adoConnection.Close
>
> ===========
>


I believe the script will dump out all users, but if the scriptPath
attribute has no value, strScript may be null, which could raise an error. I
would suggest appending a blank string to prevent this. For example:

strScript = adoRecordset.Fields("scriptPath").value & ""

Next, if you want to only document users that have no value assigned to
scriptPath, use this filter:

strFilter = "(&(objectCategory=person)(objectClass=user)(!scri ptPath=*))"

If you only want to document users that have a value assigned to scriptPath,
use:

strFilter = "(&(objectCategory=person)(objectClass=user)(scrip tPath=*))"

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Phil McNeill
Guest
Posts: n/a

 
      08-14-2008

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:ez7gceW$...
>>

>
> I believe the script will dump out all users,


You're correct, it does. My bad. I had generated the CSV a few weeks back,
edited out the users with no value in the scripts column, and forgotten I'd
edited it.

Time for a holiday...

Thank you!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dumping logon name and logon script values to a file Phil McNeill Scripting 4 06-11-2008 04:56 PM
GP Logon Scripts VS Logon Script In users Properties AJ Active Directory 1 07-10-2006 09:12 PM
Update file through logon script Craig Scripting 1 11-15-2005 11:55 AM
Re: VBS Logon Script not always executing upon logon on TS Olaf Engelke [MVP Windows Server] Active Directory 2 07-05-2005 07:05 PM
where to save logon script file?? Active Directory 3 06-21-2004 05:51 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59