I wrote a script to pull printer name, serial number and page counts from our
printers. How can I save the results to a text file?

This is the script:
Model = "mib-2.43.5.1.1.16.1"
SerialNumber = "mib-2.43.5.1.1.17.1"
PageCount = "mib-2.43.10.2.1.4.1.1"

Host = "C:\testhost.txt"


Set objfso = CreateObject("Scripting.FileSystemObject")
Set exec = CreateObject("WScript.Shell")


Set hostw = objfso.OpenTextFile(host, 1, True)

Do Until hostw.AtEndOfStream
r = hostw.ReadLine
WScript.Echo "start here"
WScript.Echo r


Set Loger = exec.Exec("snmpwalk -v 1 -c public " & r & " " & Model)
b = Loger.stdout.readall
WScript.Echo Replace(b, "SNMPv2-SMI:: = STRING: "& Model,"")

Set Loger2 = exec.Exec("snmpwalk -v 1 -c public " & r & " " & SerialNumber)
b2 = Loger2.stdout.readall
WScript.Echo Replace(b2, "SNMPv2-SMI:: = STRING: "& SerialNumber,"")

Set Loger3 = exec.Exec("snmpwalk -v 1 -c public " & r & " " & PageCount)
b3 = Loger3.stdout.readall
WScript.Echo Replace(b3, "SNMPv2-SMI:: = counter32: "& PageCount,"")
Loop

Re: Save script output to a text file by Pegasus

Pegasus
Tue May 06 00:05:05 CDT 2008


"IAGTech" <IAGTech@discussions.microsoft.com> wrote in message
news:C09FB8BD-B79D-4CFF-AB90-2CCE6EA9D54D@microsoft.com...
>I wrote a script to pull printer name, serial number and page counts from
>our
> printers. How can I save the results to a text file?
>
> This is the script:
> Model = "mib-2.43.5.1.1.16.1"
> SerialNumber = "mib-2.43.5.1.1.17.1"
> PageCount = "mib-2.43.10.2.1.4.1.1"
>
> Host = "C:\testhost.txt"
>
>
> Set objfso = CreateObject("Scripting.FileSystemObject")
> Set exec = CreateObject("WScript.Shell")
>
>
> Set hostw = objfso.OpenTextFile(host, 1, True)
>
> Do Until hostw.AtEndOfStream
> r = hostw.ReadLine
> WScript.Echo "start here"
> WScript.Echo r
>
>
> Set Loger = exec.Exec("snmpwalk -v 1 -c public " & r & " " & Model)
> b = Loger.stdout.readall
> WScript.Echo Replace(b, "SNMPv2-SMI:: = STRING: "& Model,"")
>
> Set Loger2 = exec.Exec("snmpwalk -v 1 -c public " & r & " " &
> SerialNumber)
> b2 = Loger2.stdout.readall
> WScript.Echo Replace(b2, "SNMPv2-SMI:: = STRING: "& SerialNumber,"")
>
> Set Loger3 = exec.Exec("snmpwalk -v 1 -c public " & r & " " & PageCount)
> b3 = Loger3.stdout.readall
> WScript.Echo Replace(b3, "SNMPv2-SMI:: = counter32: "& PageCount,"")
> Loop

The simplest way is to use redirection:

cscript //nologo c:\Scripts\YourScript.vbs > c:\Output.txt