Page 1 of 1 1
Topic Options
#159238 - 2006-03-16 06:29 PM writing results to text file
Jeff7492 Offline
Lurker

Registered: 2006-01-26
Posts: 3
A newbie here! I have merged many example scripts into one that I can run from a command prompt. The script asks to enter a computer name to search for on the network and uses WMI to get general info on the computer (OS version, IP info, disk info, etc) and it display this info in the dos window.

My question is: How can I add code to have it write this info to a text file that I can store and/or print out? I've tried simply redirecting at command prompt, but that doesn't work.

Background: My intension isn't to have every PC write this info upon booting. When I need the info, it will be nice to just run the script and get it.

Here is the script. Thanks in advance. Any other pointers / suggestions are welcomed.

===========================================================================================
;
; Script Information
;
; Title:
; Author:
; Description:
;
;
; ===========================================================================================
? "Enter computer name: " Gets $Computer
$WMI = GetObject ("winmgmts:\\" + $Computer + "\root\cimv2")
$Win32_OS = $WMI.InstancesOf ("Win32_OperatingSystem")

For Each $Item in $win32_OS
? "Computer Name is: " + $Item.CSName
? "Operating System is: " + $Item.Caption
? "Service Pack Levelis: " + $Item.CSDVersion
? "Install Date is: " + $Item.InstallDate
? "Last Bootup Time was: " + $Item.LastBootUpTime
? "Local Date - Time is: " + $Item.LocalDateTime
? "OS Language Number is: " + $Item.OSLanguage
? "Registered User is: " + $Item.RegisteredUser
? "Registered Company is: " + $Item.Organization
Next
? "Free Space on " $Computer ": "(GetDiskSpace("\\" + $Computer + "\C$$") / 1024) "mb"
$WMI = GetObject("winmgmts:\\" + $Computer + "\root\cimv2")
$HardDrives = $WMI.ExecQuery("Select * from Win32_LogicalDisk
Where DriveType=3")
For Each $Drive in $HardDrives
? "Drive Letter: " $Drive.Name
? "Drive Space: " $Drive.Size
? "Drive Free Space: " $Drive.FreeSpace
Next
If MemorySize() < 247
? $Computer + " is using a machine with far to little memory. Please add it to the list of computers requiring upgrades."
EndIf
If MemorySize() > 248
? $Computer + " has enough memory."
EndIf
$WMI = GetObject("winmgmts:\\" + $Computer + "\root\cimv2")
$Items = $WMI.ExecQuery("Select * from
Win32_LogicalMemoryConfiguration",,48)
For Each $Item in $Items
? "Total Physical Memory: " $Item.TotalPhysicalMemory " KB"
Next
$WMI = GetObject ("winmgmts:\\" + $Computer + "\root\cimv2")
$NICs = $WMI.ExecQuery ("Select * from
Win32_NetworkAdapterConfiguration",,48)
For Each $NICInfo in $NICs
?
For Each $Detail in $NICinfo.IPAddress
? "IP Address: " + $Detail
Next
For Each $Detail in $NICinfo.IPSubnet
? "IP Subnet: " + $Detail
Next
For Each $Detail in $NICinfo.DefaultIPGateway
? "Default IP Gateway: " + $Detail
Next
Next

Top
#159239 - 2006-03-16 07:13 PM Re: writing results to text file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You have two choices... The manual says:
Code:
RedirectOutput( )

Action: Allows you to redirect all screen output to a file.

Syntax: REDIRECTOUTPUT ("file name", overwrite)

Parameters: File name
A string that names the file to which to redirect the output. If this parameter is an empty string (""), output is redirected to the screen.

Overwrite (optional)

Optional numeric value indicating whether to clear the output file before writing any data to it. This parameter can have the following values:

0 New output data appended to the existing contents of file.
1 All data in file overwritten when the output is redirected to the file.

Remarks: If all output is redirected to a file, the AT, BIG, BOX, and CLS commands are ignored.

Returns: 0 Output redirected
Error code Function failed

REG_MULTI_SZ (multi-string) variables are returned with the pipe symbol ( | ) used as the separator between strings. If a string contains a pipe symbol character, it is represented by two pipe symbol characters ( || ).

REG_DWORD variables are returned in decimal format.

Example: IF RedirectOutput("logon.log") = 0
? "Opened 'logon.log' at " + @TIME ?
ENDIF




or you could use a UDF such as WriteLog which can be found in the UDF library.

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=82447
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#159240 - 2006-03-16 07:29 PM Re: writing results to text file
Jeff7492 Offline
Lurker

Registered: 2006-01-26
Posts: 3
Thanks so much! Works like a charm!
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.059 seconds in which 0.032 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org