Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Help desperately needed.

Reply
 
Old 01-22-2009   #1 (permalink)
Gunna


 
 

Help desperately needed.

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.

My System SpecsSystem Spec
Old 01-22-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Help desperately needed.


"Gunna" <Gunna@xxxxxx> wrote in message
news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

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


My System SpecsSystem Spec
Old 01-23-2009   #3 (permalink)
Tasha


 
 

Re: Help desperately needed.

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@xxxxxx> wrote in
message news:eYGTQ%23QfJHA.1288@xxxxxx
Quote:

>
> "Gunna" <Gunna@xxxxxx> wrote in message
> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

>>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
> --
>
>
My System SpecsSystem Spec
Old 01-23-2009   #4 (permalink)
Al Dunbar


 
 

Re: Help desperately needed.


"Gunna" <Gunna@xxxxxx> wrote in message
news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

>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


My System SpecsSystem Spec
Old 01-23-2009   #5 (permalink)
Richard Mueller [MVP]


 
 

Re: Help desperately needed.

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@xxxxxx> wrote in message
news:edza5uVfJHA.4932@xxxxxx
Quote:

> 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@xxxxxx> wrote in
> message news:eYGTQ%23QfJHA.1288@xxxxxx
Quote:

>>
>> "Gunna" <Gunna@xxxxxx> wrote in message
>> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

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

My System SpecsSystem Spec
Old 01-26-2009   #6 (permalink)
Gunna


 
 

Re: Help desperately needed.

Thats great thanks but its only half what i need. How do i output the info
to a csv file?

"Richard Mueller [MVP]" wrote:
Quote:

>
> "Gunna" <Gunna@xxxxxx> wrote in message
> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

> >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
> --
>
>
>
My System SpecsSystem Spec
Old 01-26-2009   #7 (permalink)
Monitor


 
 

Re: Help desperately needed.

Richard's detailed reply gave you 98% of what you need. You can easily put
in the remaining 2% by looking at the WriteLine method of the File System
Object. There is an example in the help file "script56.chm" which you can
download from the Microsoft site. Unless, of course, you prefer to use this
newsgroup as a free pizza delivery service, with the respondents doing all
the work for out out of the goodness of their hearts.


"Gunna" <Gunna@xxxxxx> wrote in message
news:08E35BCA-4ACF-48C4-9401-934F6E858588@xxxxxx
Quote:

> Thats great thanks but its only half what i need. How do i output the
info
Quote:

> to a csv file?
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

> >
> > "Gunna" <Gunna@xxxxxx> wrote in message
> > news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

> > >I need a simple script that will export from a certain OU (including
sub
Quote:
Quote:
Quote:

> > >OUs)
> > > the sameaccountname and displayname values for all users into a CSV
file.
Quote:
Quote:
Quote:

> > >
> > > Sounds simple enought right, not for my with no vbscript skills.
You'd
Quote:
Quote:
Quote:

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

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

> > single double quote character. The string """,""" resolves to ",".
> >
> > As with most administrative scripts, this should be run at a command
prompt
Quote:
Quote:

> > using cscript. The output should be redirected to a text file, the csv
file.
Quote:
Quote:

> > For example, if the VBScript code is saved in file GetUsers.vbs, you
could
Quote:
Quote:

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

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

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

My System SpecsSystem Spec
Old 01-26-2009   #8 (permalink)
Richard Mueller [MVP]


 
 

Re: Help desperately needed.

Look at my first post in this thread, where I describe how you can redirect
the output to a csv file.

Alternatively, you can use the FileSystemObject to write the lines to a
file, but that involves adding several lines to the program.

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

"Gunna" <Gunna@xxxxxx> wrote in message
news:08E35BCA-4ACF-48C4-9401-934F6E858588@xxxxxx
Quote:

> Thats great thanks but its only half what i need. How do i output the
> info
> to a csv file?
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

>>
>> "Gunna" <Gunna@xxxxxx> wrote in message
>> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
Quote:

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

My System SpecsSystem Spec
Old 01-27-2009   #9 (permalink)
Gunna


 
 

Re: Help desperately needed.

Richard,

You are correct apollogies for that. I did read that initially and then it
slipped my mind. That's what happens when you given a job that is totally
outside of your skill set. Thanks for the suggestion of the Filesystemobject
function, it worked. You have been very helpful unlike some others in this
forum who odviously get their kicks from being arrogant and a smart arse at
the expence of others, you know who you are.

"Richard Mueller [MVP]" wrote:
Quote:

> Look at my first post in this thread, where I describe how you can redirect
> the output to a csv file.
>
> Alternatively, you can use the FileSystemObject to write the lines to a
> file, but that involves adding several lines to the program.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Gunna" <Gunna@xxxxxx> wrote in message
> news:08E35BCA-4ACF-48C4-9401-934F6E858588@xxxxxx
Quote:

> > Thats great thanks but its only half what i need. How do i output the
> > info
> > to a csv file?
> >
> > "Richard Mueller [MVP]" wrote:
> >
Quote:

> >>
> >> "Gunna" <Gunna@xxxxxx> wrote in message
> >> news:00BC02EA-F8D9-4509-9274-0CAD57AD44A5@xxxxxx
> >> >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
> >> --
> >>
> >>
> >>
>
>
>
My System SpecsSystem Spec
Old 01-27-2009   #10 (permalink)
Monitor


 
 

Re: Help desperately needed.


"Gunna" <Gunna@xxxxxx> wrote in message
news:FFC6C726-889D-4654-AD59-B710E097F2E6@xxxxxx
Quote:

> Richard,
>
> You are correct apollogies for that. I did read that initially and then
it
Quote:

> slipped my mind. That's what happens when you given a job that is totally
> outside of your skill set. Thanks for the suggestion of the
Filesystemobject
Quote:

> function, it worked. You have been very helpful unlike some others in
this
Quote:

> forum who odviously get their kicks from being arrogant and a smart arse
at
Quote:

> the expence [expense] of others, you know who you are.
A sharp kick in the bum to remind someone of his responsibilities can work
miracles. It certainly worked in your case.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Desperately Need Help! General Discussion
Not sure where to post this but I desperately need help. General Discussion
IE Issue - Desperately Need Help! Vista General
Desperately Need Help - Difficult Issue Vista General
stupid, stupid Microsoft [MAC access control desperately needed!] Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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