Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Re: Issue with Getting Output Data to txt or csv file

Reply
Thread Tools Display Modes

Re: Issue with Getting Output Data to txt or csv file

 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      09-09-2009

"jamiejambo" <> wrote in message
news:...
>
> Hi Guys
> Looking for some help. I have the script below and I am trying to
> output the data to a txt or csv file but I do not know how to do it.
> Please could someone help.
>
> Option Explicit
>
> Dim strFilePath, objFSO, objFile, objRootDSE
> Dim strDNSDomain, objTrans, strNetBIOSDomain
> Dim strNTName, strUserDN, objUser
>
> Const ForReading = 1
> ' Constants for NameTranslate.
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
> ' Specify the text file of user names.
> strFilePath = "C:\Documents and Settings\joh149\bulk.txt"
>
> ' Open the file for read access.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)
>
> ' Determine DNS domain name from RootDSE object.
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
>
> ' Use the NameTranslate object to find the NetBIOS domain name
> ' from the DNS domain name.
> Set objTrans = CreateObject("NameTranslate")
> objTrans.Init ADS_NAME_INITTYPE_GC, ""
> objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> ' Remove trailing backslash.
> strNetBIOSDomain = Left(strNetBIOSDomain, _
> Len(strNetBIOSDomain) - 1)
>
> ' Read NT names from text file.
> Do Until objFile.AtEndOfStream
> strNTName = Trim(objFile.ReadLine)
> ' Skip blank lines.
> If (strNTName <> "") Then
> ' Use Set method to specify NT name.
> ' Trap error if name not found.
> On Error Resume Next
> objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
> If (Err.Number <> 0) Then
> On Error GoTo 0
> Wscript.Echo "User " & strNTName _
> & " not found in Active Directory"
> End If
> On Error GoTo 0
> ' Use Get method to retrieve Distinguished Name.
> strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
> ' Bind to user object in AD.
> Set objUser = GetObject("LDAP://" & strUserDN)
> ' Output values desired. This outputs:
> ' NT Name;Common Name;first name;last name;street;city;
> wscript.Echo objUser.sAMAccountName _
> & ";" & objUser.sn _
> & ";" & objUser.givenName _
> & ";" & objUser.l _
> & ";" & objUser.c _
> & ";" & objUser.title _
> & ";" & objUser.company _
> & ";" & objUser.department _
> & ";" & objUser.physicaldeliveryofficename
> End If
> Loop
> objFile.Close
> --
> jamiejambo


Since you already generate an output with the wscript.echo method, the
simplest way is to invoke your script like so:

cscript //nologo c:\jambo.vbs > c:\output.txt


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista64 Perfrom - Data collector output to local SQL Jarryd Windows Vista Performance 1 03-27-2009 10:58 AM
Print to File/Output file name issue DocD514 Windows Vista Printing / Faxing / Scanning 3 11-14-2008 10:13 PM
how to change data output in TestCap Example on DDK David Windows Vista Drivers 0 06-21-2006 10:27 AM
remotely executed script calls batch file that redirects output to a txt file reference by UNC path Breck Scripting 2 11-02-2004 06:00 PM
output to TV (quality issue) david cleland Windows Media Center 10 08-02-2004 09:08 AM



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 47 48 49 50 51 52 53 54 55 56 57 58 59