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

Discussion in 'Scripting' started by Phil McNeill, Aug 13, 2008.

  1. Phil McNeill

    Phil McNeill Guest

    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

    ===========
     
    Phil McNeill, Aug 13, 2008
    #1
    1. Advertisements

  2. 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)(!scriptPath=*))"

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

    strFilter = "(&(objectCategory=person)(objectClass=user)(scriptPath=*))"
     
    Richard Mueller [MVP], Aug 13, 2008
    #2
    1. Advertisements

  3. Phil McNeill

    Phil McNeill Guest

    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!
     
    Phil McNeill, Aug 14, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.