![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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. 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 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 Quote: Quote: Quote: > > >OUs) > > > the sameaccountname and displayname values for all users into a CSV Quote: Quote: Quote: > > > > > > Sounds simple enought right, not for my with no vbscript skills. 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 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 Quote: Quote: > > single double quote character. The string """,""" resolves to ",". > > > > As with most administrative scripts, this should be run at a command Quote: Quote: > > using cscript. The output should be redirected to a text file, the csv Quote: Quote: > > For example, if the VBScript code is saved in file GetUsers.vbs, you 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 Quote: Quote: > > the file. > > > > You can also use Joe Richards' free adfind utility for this. See this 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 Specs![]() |
| | #8 (permalink) |
| | 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 Specs![]() |
| | #9 (permalink) |
| | 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 Specs![]() |
| | #10 (permalink) |
| | 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 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 Quote: > function, it worked. You have been very helpful unlike some others in Quote: > forum who odviously get their kicks from being arrogant and a smart arse Quote: > the expence [expense] of others, you know who you are. miracles. It certainly worked in your case. |
My System Specs![]() |
![]() |
| 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 | |||