Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Output results in a text file instead of display on screen

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,31951
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Output results in a text file instead of display on screen
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Output results in a text file instead of display on screen - 3/7/2006 4:23:50 AM   
  NewBee

 

Posts: 32
Score: 0
Joined: 2/10/2006
Status: offline
hello

just wanted to find out how can i make the script below to out put the information to a text file instead of displaying it on the screen

thanks in advance,

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
Wscript.Echo "Computer Name: " & objOS.CSName
Wscript.Echo "Caption: " & objOS.Caption 'Name
Wscript.Echo "Version: " & objOS.Version 'Version & build
Wscript.Echo "Build Number: " & objOS.BuildNumber 'Build
Wscript.Echo "Build Type: " & objOS.BuildType
Wscript.Echo "OS Type: " & objOS.OSType
Wscript.Echo "Other Type Description: " & objOS.OtherTypeDescription
WScript.Echo "Service Pack: " & objOS.ServicePackMajorVersion & "." & _
  objOS.ServicePackMinorVersion
Next
 
 
Post #: 1
 
 RE: Output results in a text file instead of display on... - 3/7/2006 4:40:06 AM   
  led203

 

Posts: 1
Score: 0
Joined: 3/7/2006
Status: offline
The following is code that I tested on my system and it works great - thanks for giving me the Idea!

LarryD

===========================================
On Error Resume Next
Dim objFileSystem, objOutputFile
Dim strOutputFile

Const OPEN_FILE_FOR_APPENDING = 8

' Specify the File Name
strOutputFile = "\\server\directory\PC_Stats.log"

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFileSystem = CreateObject("Scripting.fileSystemObject")

'Open the File
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, OPEN_FILE_FOR_APPENDING)

'If the file does NOT exist - then create it
If err.number = 53 then Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOS in colOSes
     objOutputFile.WriteLine("Computer Name: " & objOS.CSName )
     objOutputFile.WriteLine("Caption: " & objOS.Caption) 'Name
     objOutputFile.WriteLine("Version: " & objOS.Version) 'Version & build
     objOutputFile.WriteLine("Build Number: " & objOS.BuildNumber) 'Build
     objOutputFile.WriteLine("Build Type: " & objOS.BuildType )
     objOutputFile.WriteLine("OS Type: " & objOS.OSType )
     objOutputFile.WriteLine("Other Type Description: " & objOS.OtherTypeDescription )
     objOutputFile.WriteLine("Service Pack: " & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion )
     objOutputFile.WriteLine(vbcrlf) 'Just for Readability
Next

'Close the file
objOutputFile.Close

(in reply to NewBee)
 
 
Post #: 2
 
 RE: Output results in a text file instead of display on... - 3/7/2006 7:07:01 AM   
  hamboy

 

Posts: 94
Score: 6
Joined: 7/11/2005
Status: offline
This should work..


      

(in reply to led203)
 
 
Post #: 3
 
 RE: Output results in a text file instead of display on... - 3/7/2006 8:43:38 AM   
  NewBee

 

Posts: 32
Score: 0
Joined: 2/10/2006
Status: offline
thanks for your inputs,  i have taken the script and added manufacture, model, physical memory and CPU info.  this is very handy script for system admins that need to collect info about their servers

On Error Resume Next
Dim objFileSystem, objOutputFile
Dim strOutputFile
Const OPEN_FILE_FOR_APPENDING = 8
' Specify the File Name
strOutputFile = "\\server name\share\PC_Stats.log"
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
'Open the File
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, OPEN_FILE_FOR_APPENDING)
'If the file does NOT exist - then create it
If err.number = 53 then Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
strComputer = "computer name"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
Set colCSItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objItem In colItems
    objOutputFile.WriteLine"Computer Name: " & objItem.Name
    objOutputFile.WriteLine"Manufacturer: " & objItem.Manufacturer
    objOutputFile.WriteLine"Model: " & objItem.Model
next
For Each objCSItem In colCSItems
    objOutputFile.WriteLine"Total Physical Memory: " & objCSItem.TotalPhysicalMemory
Next
For Each objOS in colOSes
    objOutputFile.WriteLine"Caption: " & objOS.Caption 'Name
    objOutputFile.WriteLine"Version: " & objOS.Version 'Version & build
    objOutputFile.WriteLine"Build Number: " & objOS.BuildNumber 'Build
    objOutputFile.WriteLine"Build Type: " & objOS.BuildType
    objOutputFile.WriteLine"OS Type: " & objOS.OSType
    objOutputFile.WriteLine"Other Type Description: " & objOS.OtherTypeDescription
    objOutputFile.WriteLine"Service Pack: " & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion
    objOutputFile.WriteLine"Computer Name: " & objCS.Name
    objOutputFile.WriteLine"System Type: " & objCS.SystemType
    objOutputFile.WriteLine"Number Of Processors: " & objCS.NumberOfProcessors
Next
Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objProcessor in colProcessors
    objOutputFile.WriteLine"Manufacturer: " & objProcessor.Manufacturer
    objOutputFile.WriteLine"Name: " & objProcessor.Name
    objOutputFile.WriteLine"Description: " & objProcessor.Description
    objOutputFile.WriteLine"Processor ID: " & objProcessor.ProcessorID
    objOutputFile.WriteLine"Address Width: " & objProcessor.AddressWidth
    objOutputFile.WriteLine"Data Width: " & objProcessor.DataWidth
    objOutputFile.WriteLine"Family: " & objProcessor.Family
    objOutputFile.WriteLine"Maximum Clock Speed: " & objProcessor.MaxClockSpeed
    objOutputFile.WriteLine(vbcrlf) 'Just for Readability
   
Next
'Close the file
objOutputFile.Close

(in reply to NewBee)
 
 
Post #: 4
 
 RE: Output results in a text file instead of display on... - 3/7/2006 9:29:29 AM   
  vbsnovice

 

Posts: 21
Score: 0
Joined: 11/1/2005
Status: offline
Hi all,

Here is another way of getting a Network Computer Inventory info in your domain, I found this script very handy when the need arises. There are 2 seperate scripts involved in this procedure:
1. Create-IP-Table.vbs and
2. SMS-PC-Inventory.vbs
Enjoy...


Script 1. Create-IP-Table

      
Script 2. SMS-PC-Inventory.vbs

      

< Message edited by vbsnovice -- 3/7/2006 9:51:20 AM >


_____________________________

Cheers,
VBSnovice

(in reply to NewBee)
 
 
Post #: 5
 
 RE: Output results in a text file instead of display on... - 3/7/2006 9:37:02 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Please, please, please edit your post and put your code into a [code][/code] block or simply highlight all of your code and click the <% button just above the edit box. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to vbsnovice)
 
 
Post #: 6
 
 RE: Output results in a text file instead of display on... - 3/7/2006 9:52:22 AM   
  vbsnovice

 

Posts: 21
Score: 0
Joined: 11/1/2005
Status: offline
Oops, sorry dude! please dont get mad at me as I'm just a novice

_____________________________

Cheers,
VBSnovice

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Output results in a text file instead of display on... - 3/7/2006 9:54:13 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Not mad, just need to buy a new scroll wheel for my mouse now. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to vbsnovice)
 
 
Post #: 8
 
 RE: Output results in a text file instead of display on... - 3/7/2006 9:59:48 AM   
  vbsnovice

 

Posts: 21
Score: 0
Joined: 11/1/2005
Status: offline
ebgreen, I got a spare MS InteliMouse would you like me to email you?

_____________________________

Cheers,
VBSnovice

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Output results in a text file instead of display on... - 3/7/2006 10:02:32 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
I think I should be able to muddle through, thanks though. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to vbsnovice)
 
 
Post #: 10
 
 RE: Output results in a text file instead of display on... - 3/7/2006 10:04:41 AM   
  vbsnovice

 

Posts: 21
Score: 0
Joined: 11/1/2005
Status: offline
No thank You , I've learned a lot of tricks from you guys, thanks everyone in this super forum.

_____________________________

Cheers,
VBSnovice

(in reply to ebgreen)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Output results in a text file instead of display on screen Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts