dumping logon name and logon script values to a file

Discussion in 'Scripting' started by Phil McNeill, Jun 6, 2008.

  1. Phil McNeill

    Phil McNeill Guest

    I am looking to be able to dump each of my user's logon names, along with
    the value in their respective "Logon script" fields in their 2003 AD profile
    (i.e. the name of their logon script) to a csv file so that I end up with
    two columns, one with every logon name in the domain and the other with the
    corresponding scripts names.

    Any help would be greatly appreciated. Thanks!

    Phil
     
    Phil McNeill, Jun 6, 2008
    #1
    1. Advertisements

  2. Try this line:
    echo "%UserName%","%ComputerName%","%0" >>
    \\YourServer\SomeShare\SomeFolder\logon.log
     
    Pegasus \(MVP\), Jun 6, 2008
    #2
    1. Advertisements

  3. Phil McNeill

    Wiseman82 Guest

    Wiseman82, Jun 7, 2008
    #3
  4. There are some command line tools that can do this. For example Joe
    Richards' adfind:

    http://www.joeware.net/freetools/tools/adfind/index.htm

    The attributes of the user objects you want are "sAMAccountName"
    (pre-Windows 2000 logon name) and "scriptPath". A VBScript program can use
    ADO to retrieve this information. It can be output in comma delimited lines.
    You can redirect the output to a text file, which can be opened by a
    spreadsheet program. For more information on using ADO in scripts see this
    link:

    http://www.rlmueller.net/ADOSearchTips.htm

    For example, to retrieve sAMAccountName and scriptPath for all users in the
    domain:
    =============
    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

    ===========

    You would run this at a command prompt with the cscript host and redirect
    the output to a text file. If the script is saved in the file Example.vbs,
    the command could be:



    cscript //nologo Example.vbs > output.csv



    If the file Example.vbs is not in the current directory, you must include
    the path. The file output.csv is created in the current directory. The
    optional "//nologo" parameter suppresses logo information so it is not in
    the file.
     
    Richard Mueller [MVP], Jun 7, 2008
    #4
  5. Phil McNeill

    Phil McNeill Guest

    Thanks to everyone for the tips and pointers. These should do the trick!
     
    Phil McNeill, Jun 11, 2008
    #5
    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.