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
--