From: Gunna on
I need a simple script that will export from a certain OU (including sub OUs)
the sameaccountname and displayname values for all users into a CSV file.

Sounds simple enought right, not for my with no vbscript skills. You'd
think Google would help me but Google hates me.

Any help would be great.
From: Richard Mueller [MVP] on

"Gunna" <Gunna(a)discussions.microsoft.com> wrote in message
news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5(a)microsoft.com...
>I need a simple script that will export from a certain OU (including sub
>OUs)
> the sameaccountname and displayname values for all users into a CSV file.
>
> Sounds simple enought right, not for my with no vbscript skills. You'd
> think Google would help me but Google hates me.
>
> Any help would be great.

You can use ADO in a VBScript program for this. See this link for details:

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

For example:
==========
Option Explicit
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim strQuery, adoRecordset, strName, strDisplay

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

' Specify the base of the query.
' This is the full AdsPath of the OU.
strBase = "<LDAP://ou=West,dc=MyDomain,dc=com>"

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

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

' 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
strDisplay = adoRecordset.Fields("displayName").value
Wscript.Echo """" & strName & """,""" & strDisplay & """"
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close
=========
I quoted the values in case they have embedded commas. The double quote
character must be doubled in a quoted string. The string """" resolves to a
single double quote character. The string """,""" resolves to ",".

As with most administrative scripts, this should be run at a command prompt
using cscript. The output should be redirected to a text file, the csv file.
For example, if the VBScript code is saved in file GetUsers.vbs, you could
use the following command to create report.csv:

cscript //nologo GetUsers.vbs > report.csv

If GetUsers.vbs is not in the current directory, include the full path to
the file.

You can also use Joe Richards' free adfind utility for this. See this link:

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

I think the command would be similar to (one line):

adfind -b "ou=West,dc=MyDomain,dc=com" -f
"(&(objectCategory=person)(objectClass=user))" -nodn -csv sAMAccountName
displayName

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


From: Tasha on
Good morning!

Richard - this is more intended for you.....

Instead of using "(&(objectCategory=person)(objectClass=user))" do you see
any problem with using "(sAMAccountType=805306368)"?

I use that all the time and it works very well....it does not include
contacts and whatnot....but I doubt that this is an issu in this particular
case.

I would be interested in your thoughts on this.

Thanks,

Cary


"Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in
message news:eYGTQ%23QfJHA.1288(a)TK2MSFTNGP02.phx.gbl...
>
> "Gunna" <Gunna(a)discussions.microsoft.com> wrote in message
> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5(a)microsoft.com...
>>I need a simple script that will export from a certain OU (including sub
>>OUs)
>> the sameaccountname and displayname values for all users into a CSV file.
>>
>> Sounds simple enought right, not for my with no vbscript skills. You'd
>> think Google would help me but Google hates me.
>>
>> Any help would be great.
>
> You can use ADO in a VBScript program for this. See this link for details:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> For example:
> ==========
> Option Explicit
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
> Dim strQuery, adoRecordset, strName, strDisplay
>
> ' Setup ADO objects.
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> adoCommand.ActiveConnection = adoConnection
>
> ' Specify the base of the query.
> ' This is the full AdsPath of the OU.
> strBase = "<LDAP://ou=West,dc=MyDomain,dc=com>"
>
> ' Filter on user objects.
> strFilter = "(&(objectCategory=person)(objectClass=user))"
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "sAMAccountName,displayName"
>
> ' 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
> strDisplay = adoRecordset.Fields("displayName").value
> Wscript.Echo """" & strName & """,""" & strDisplay & """"
> ' Move to the next record in the recordset.
> adoRecordset.MoveNext
> Loop
>
> ' Clean up.
> adoRecordset.Close
> adoConnection.Close
> =========
> I quoted the values in case they have embedded commas. The double quote
> character must be doubled in a quoted string. The string """" resolves to
> a single double quote character. The string """,""" resolves to ",".
>
> As with most administrative scripts, this should be run at a command
> prompt using cscript. The output should be redirected to a text file, the
> csv file. For example, if the VBScript code is saved in file GetUsers.vbs,
> you could use the following command to create report.csv:
>
> cscript //nologo GetUsers.vbs > report.csv
>
> If GetUsers.vbs is not in the current directory, include the full path to
> the file.
>
> You can also use Joe Richards' free adfind utility for this. See this
> link:
>
> http://www.joeware.net/freetools/tools/adfind/index.htm
>
> I think the command would be similar to (one line):
>
> adfind -b "ou=West,dc=MyDomain,dc=com" -f
> "(&(objectCategory=person)(objectClass=user))" -nodn -csv sAMAccountName
> displayName
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>

From: Al Dunbar on

"Gunna" <Gunna(a)discussions.microsoft.com> wrote in message
news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5(a)microsoft.com...
>I need a simple script that will export from a certain OU (including sub
>OUs)
> the sameaccountname and displayname values for all users into a CSV file.
>
> Sounds simple enought right, not for my with no vbscript skills. You'd
> think Google would help me but Google hates me.

Are you sure that your need is for a script to do this? Or would you be
happy with something other than a script that does this? If the latter,
consider CSVDE:

http://computerperformance.co.uk/Logon/Logon_CSVDE.htm

/Al


From: Richard Mueller [MVP] on
Your filter is actually more efficient (because objectClass is not indexed).
It's just harder to remember. It yields the same results.

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

"Tasha" <tasha(a)nowhere.com> wrote in message
news:edza5uVfJHA.4932(a)TK2MSFTNGP02.phx.gbl...
> Good morning!
>
> Richard - this is more intended for you.....
>
> Instead of using "(&(objectCategory=person)(objectClass=user))" do you see
> any problem with using "(sAMAccountType=805306368)"?
>
> I use that all the time and it works very well....it does not include
> contacts and whatnot....but I doubt that this is an issu in this
> particular case.
>
> I would be interested in your thoughts on this.
>
> Thanks,
>
> Cary
>
>
> "Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in
> message news:eYGTQ%23QfJHA.1288(a)TK2MSFTNGP02.phx.gbl...
>>
>> "Gunna" <Gunna(a)discussions.microsoft.com> wrote in message
>> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5(a)microsoft.com...
>>>I need a simple script that will export from a certain OU (including sub
>>>OUs)
>>> the sameaccountname and displayname values for all users into a CSV
>>> file.
>>>
>>> Sounds simple enought right, not for my with no vbscript skills. You'd
>>> think Google would help me but Google hates me.
>>>
>>> Any help would be great.
>>
>> You can use ADO in a VBScript program for this. See this link for
>> details:
>>
>> http://www.rlmueller.net/ADOSearchTips.htm
>>
>> For example:
>> ==========
>> Option Explicit
>> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
>> Dim strQuery, adoRecordset, strName, strDisplay
>>
>> ' Setup ADO objects.
>> Set adoCommand = CreateObject("ADODB.Command")
>> Set adoConnection = CreateObject("ADODB.Connection")
>> adoConnection.Provider = "ADsDSOObject"
>> adoConnection.Open "Active Directory Provider"
>> adoCommand.ActiveConnection = adoConnection
>>
>> ' Specify the base of the query.
>> ' This is the full AdsPath of the OU.
>> strBase = "<LDAP://ou=West,dc=MyDomain,dc=com>"
>>
>> ' Filter on user objects.
>> strFilter = "(&(objectCategory=person)(objectClass=user))"
>>
>> ' Comma delimited list of attribute values to retrieve.
>> strAttributes = "sAMAccountName,displayName"
>>
>> ' 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
>> strDisplay = adoRecordset.Fields("displayName").value
>> Wscript.Echo """" & strName & """,""" & strDisplay & """"
>> ' Move to the next record in the recordset.
>> adoRecordset.MoveNext
>> Loop
>>
>> ' Clean up.
>> adoRecordset.Close
>> adoConnection.Close
>> =========
>> I quoted the values in case they have embedded commas. The double quote
>> character must be doubled in a quoted string. The string """" resolves to
>> a single double quote character. The string """,""" resolves to ",".
>>
>> As with most administrative scripts, this should be run at a command
>> prompt using cscript. The output should be redirected to a text file, the
>> csv file. For example, if the VBScript code is saved in file
>> GetUsers.vbs, you could use the following command to create report.csv:
>>
>> cscript //nologo GetUsers.vbs > report.csv
>>
>> If GetUsers.vbs is not in the current directory, include the full path to
>> the file.
>>
>> You can also use Joe Richards' free adfind utility for this. See this
>> link:
>>
>> http://www.joeware.net/freetools/tools/adfind/index.htm
>>
>> I think the command would be similar to (one line):
>>
>> adfind -b "ou=West,dc=MyDomain,dc=com" -f
>> "(&(objectCategory=person)(objectClass=user))" -nodn -csv sAMAccountName
>> displayName
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>


 |  Next  |  Last
Pages: 1 2
Prev: Populating ComboBox
Next: Vbscript to Search Excel