![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | How to a CSV file in a VBS Script I am looking for a little help on how to take the script below and put the results in a CSV file. I got this script from the Microsoft Scriptcenter and it displays all the members of an Active Directory Group. On Error Resume Next Set objGroup = GetObject _ ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") objGroup.GetInfo arrMemberOf = objGroup.GetEx("member") WScript.Echo "Members:" For Each strMember in arrMemberOf WScript.echo strMember Next |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to a CSV file in a VBS Script On Aug 11, 2:48 pm, rademr1 <rade...@xxxxxx> wrote: Quote: > I am looking for a little help on how to take the script below and put the > results in a CSV file. I got this script from the Microsoft Scriptcenter and > it displays all the members of an Active Directory Group. > > On Error Resume Next > > Set objGroup = GetObject _ > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") > objGroup.GetInfo > > arrMemberOf = objGroup.GetEx("member") > > WScript.Echo "Members:" > For Each strMember in arrMemberOf > WScript.echo strMember > Next sFilespec = "D:\Someplace\SomefileName.csv" Set fso = CreateObject("Scripting.FileSystemObject") set oCSV = fso.opentextfile(sFilespec, 1) Set objGroup = GetObject _ ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") objGroup.GetInfo arrMemberOf = objGroup.GetEx("member") oCSV.Writeline "Members" For Each strMember in arrMemberOf oCSV.Writeline strMember Next oCSV.close Tom Lavedas =========== http://members.cox.net/tglbatch/wsh/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to a CSV file in a VBS Script "Tom Lavedas" wrote: Quote: > On Aug 11, 2:48 pm, rademr1 <rade...@xxxxxx> wrote: Quote: > > I am looking for a little help on how to take the script below and put the > > results in a CSV file. I got this script from the Microsoft Scriptcenter and > > it displays all the members of an Active Directory Group. > > > > On Error Resume Next > > > > Set objGroup = GetObject _ > > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") > > objGroup.GetInfo > > > > arrMemberOf = objGroup.GetEx("member") > > > > WScript.Echo "Members:" > > For Each strMember in arrMemberOf > > WScript.echo strMember > > Next > Maybe ... > > sFilespec = "D:\Someplace\SomefileName.csv" > > Set fso = CreateObject("Scripting.FileSystemObject") > set oCSV = fso.opentextfile(sFilespec, 1) > > Set objGroup = GetObject _ > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") > objGroup.GetInfo > > arrMemberOf = objGroup.GetEx("member") > > oCSV.Writeline "Members" > For Each strMember in arrMemberOf > oCSV.Writeline strMember > Next > > oCSV.close > > Tom Lavedas > =========== > http://members.cox.net/tglbatch/wsh/ > settings and I got an error when I ran the script. Script: C:\members1.vbs Line: 4 Char: 1 Error: File not found Code: 800A00035 Source: Microsoft VBScript runtime error Thanks for your help. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to a CSV file in a VBS Script On Aug 11, 3:42 pm, rademr1 <rade...@xxxxxx> wrote: Quote: > "Tom Lavedas" wrote: Quote: > > On Aug 11, 2:48 pm, rademr1 <rade...@xxxxxx> wrote: Quote: > > > I am looking for a little help on how to take the script below and put the > > > results in a CSV file. I got this script from the Microsoft Scriptcenter and > > > it displays all the members of an Active Directory Group. Quote: Quote: > > > On Error Resume Next Quote: Quote: > > > Set objGroup = GetObject _ > > > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") > > > objGroup.GetInfo Quote: Quote: > > > arrMemberOf = objGroup.GetEx("member") Quote: Quote: > > > WScript.Echo "Members:" > > > For Each strMember in arrMemberOf > > > WScript.echo strMember > > > Next Quote: > > Maybe ... Quote: > > sFilespec = "D:\Someplace\SomefileName.csv" Quote: > > Set fso = CreateObject("Scripting.FileSystemObject") > > set oCSV = fso.opentextfile(sFilespec, 1) Quote: > > Set objGroup = GetObject _ > > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") > > objGroup.GetInfo Quote: > > arrMemberOf = objGroup.GetEx("member") Quote: > > oCSV.Writeline "Members" > > For Each strMember in arrMemberOf > > oCSV.Writeline strMember > > Next Quote: > > oCSV.close Quote: > I changed where the file is suppose to save and also changed the LDAP > settings and I got an error when I ran the script. > > Script: C:\members1.vbs > Line: 4 > Char: 1 > Error: File not found > Code: 800A00035 > Source: Microsoft VBScript runtime error > > Thanks for your help. set oCSV = fso.opentextfile(sFilespec, 1) should read ... set oCSV = fso.opentextfile(sFilespec, 2) The constant is ForReading = 1, ForWriting = 2 and ForAppending = 8. I put in the wrong constant. Tom Lavedas =========== http://members.cox.net/tglbatch/wsh/ |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to a CSV file in a VBS Script You might also find this script useful for listing all groups/members: http://www.wisesoft.co.uk/scripts/vb...rs_report.aspx Hope this helps, David "Tom Lavedas" <tglbatch@xxxxxx> wrote in message news:c3addbfc-fd22-4766-9a2b-8ace1e28fdd8@xxxxxx Quote: > On Aug 11, 3:42 pm, rademr1 <rade...@xxxxxx> wrote: Quote: >> "Tom Lavedas" wrote: Quote: >> > On Aug 11, 2:48 pm, rademr1 <rade...@xxxxxx> wrote: >> > > I am looking for a little help on how to take the script below and >> > > put the >> > > results in a CSV file. I got this script from the Microsoft >> > > Scriptcenter and >> > > it displays all the members of an Active Directory Group. Quote: >> > > On Error Resume Next Quote: >> > > Set objGroup = GetObject _ >> > > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") >> > > objGroup.GetInfo Quote: >> > > arrMemberOf = objGroup.GetEx("member") Quote: >> > > WScript.Echo "Members:" >> > > For Each strMember in arrMemberOf >> > > WScript.echo strMember >> > > Next Quote: >> > Maybe ... Quote: >> > sFilespec = "D:\Someplace\SomefileName.csv" Quote: >> > Set fso = CreateObject("Scripting.FileSystemObject") >> > set oCSV = fso.opentextfile(sFilespec, 1) Quote: >> > Set objGroup = GetObject _ >> > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") >> > objGroup.GetInfo Quote: >> > arrMemberOf = objGroup.GetEx("member") Quote: >> > oCSV.Writeline "Members" >> > For Each strMember in arrMemberOf >> > oCSV.Writeline strMember >> > Next Quote: >> > oCSV.close Quote: >> I changed where the file is suppose to save and also changed the LDAP >> settings and I got an error when I ran the script. >> >> Script: C:\members1.vbs >> Line: 4 >> Char: 1 >> Error: File not found >> Code: 800A00035 >> Source: Microsoft VBScript runtime error >> >> Thanks for your help. > Sorry, my fault. This line ... > > set oCSV = fso.opentextfile(sFilespec, 1) > > should read ... > > set oCSV = fso.opentextfile(sFilespec, 2) > > The constant is ForReading = 1, ForWriting = 2 and ForAppending = 8. > I put in the wrong constant. > > Tom Lavedas > =========== > http://members.cox.net/tglbatch/wsh/ |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How to a CSV file in a VBS Script "rademr1" <rademr1@xxxxxx> wrote in message news:45CAECA0-64B8-415B-8C94-428C68F60150@xxxxxx Quote: >I am looking for a little help on how to take the script below and put the > results in a CSV file. I got this script from the Microsoft Scriptcenter > and > it displays all the members of an Active Directory Group. > > On Error Resume Next > > Set objGroup = GetObject _ > ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") > objGroup.GetInfo > > arrMemberOf = objGroup.GetEx("member") > > WScript.Echo "Members:" > For Each strMember in arrMemberOf > WScript.echo strMember > Next > > to a text file. You would run the script at a command prompt using cscript. For example: cscript //nologo Example.vbs > report.txt Next, the GetEx method in your script will raise an error if the group has no members. That's why it has "On Error Resume Next". I would trap the error and echo this condition (no members) with code similar to: ========== Set objGroup = GetObject _ ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") On Error Resume Next arrMemberOf = objGroup.GetEx("member") If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "No members" Else On Error GoTo 0 WScript.Echo "Members:" For Each strMember in arrMemberOf WScript.echo strMember Next End If =========== Finally, it might make sense to use the Members method of the group object, which never raises an error. This method returns a collection of member objects (not just DN's), so you have access to all attributes of the members: ========== Set objGroup = GetObject _ ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com") For Each objMember In objGroup.Members Wscript.Echo objMember.distinguishedName Next ========== If instead you wanted to document the "pre-Windows 2000 logon" name, you could use objMember.sAMAccountName. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| VBS SCRIPT to clean OLD FILE | VB Script | |||
| file copy operations using source file input and script? | PowerShell | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||
| Can you drag-n-drop a file on top of a PS script to run the script? | PowerShell | |||