Page 1 of 1 1
Topic Options
#148649 - 2005-09-28 06:02 AM Hardware inventory to csv or excel file
alex1372 Offline
Lurker

Registered: 2005-09-25
Posts: 4
Hello,

I'm totally new for any of scripting technics and i heed help to accomplish the following:

1. I need to collect local hardware info (PC Name, IP, MAC, build date, model, chassis, logged on user, cpu speed, total memory, HDD size) in csv format (kind of easy)
2. When every time I get needed information I would like to populate excel with that info, for each computer on separate row. (have no clue )

I would like to use this routine for logging purposes when deploying new workstation.

Thank you very much.

Top
#148650 - 2005-09-28 09:40 AM Re: Hardware inventory to csv or excel file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Well, writing it to a csv file with each comp on a new line then it could be easily opened/imported into excel.
This would be the easiest way imho.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148651 - 2005-09-28 03:21 PM Re: Hardware inventory to csv or excel file
alex1372 Offline
Lurker

Registered: 2005-09-25
Posts: 4
I know how i can do it for one PC, but how can add lines from different computers to the same file?

I found script to get almost all info, but how can I add model and chassis to it?

Code:

BREAK On
$IPaddr = EnumIPinfo(0,0)
if $IPaddr = "0.0.0.0" or $IPaddr = ""
$IPinfo = GetIPinfo()
$IPaddr = $IPinfo[0]
$SNmask = $IPinfo[1]
$Gateway = $IPinfo[2]
else
$SNmask = EnumIPinfo(0,1)
$Gateway = EnumIPinfo(0,3)
endif

;Output file
$nul= ReDirectOutput ("\\server\share\hardware_inventory.csv",1)

$objWMIService = GetObject( "winmgmts://./root/cimv2" )

; Query processor properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_Processor", , 48 )
; Display results
For Each $objItem in $colItems
$mycpu = ($objItem.CurrentClockSpeed) + " MHz"
Next

; Query memory properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
; Display results
For Each $objItem in $colItems
$mymemory = ( ( $objItem.TotalPhysicalMemory + 1023 ) / 1024 )
Next

; Query harddisk properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
; Display results
For Each $objItem in $colItems
; Some trickery to enable working with large numbers
$Size = $objItem.Size
$LSize = Len( $Size )
$MSize = SubStr( $Size, 1, $LSize - 3 )
$Size = ( 524288 + $MSize ) / 1048576
Next

? "@WKSTA,@UserID,@PRODUCTTYPE @CSD,$IPaddr,@address,$mycpu,$mymemory,$Size"

Quit 0
[\code]
Top
#148652 - 2005-09-28 04:36 PM Re: Hardware inventory to csv or excel file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could do a WriteLine to the file followed by a @CRLF.
This is tricky when multiple computers want to write to the file at the same time. Same goes for redirectouput.
More save would be to let them write to an access or sql databse. Some UDF's to do this are in the UDF forum.

UDF Library
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148653 - 2005-09-28 08:20 PM Re: Hardware inventory to csv or excel file
alex1372 Offline
Lurker

Registered: 2005-09-25
Posts: 4
The script takes about 2 second to update the file. Is there a way to check (for locking) the file before opening it?
Top
#148654 - 2005-09-28 08:31 PM Re: Hardware inventory to csv or excel file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Seen something about this not long ago. If I recall correctly Richard H and Jooel talked about this. Can’t find it right now. Maybe one of them remembers where it is and can give you a push in the right direction.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148655 - 2005-09-28 10:53 PM Re: Hardware inventory to csv or excel file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
recommend writing each computer to it's own file. Then from your desktop at a DOS prompt you can do something like this. (just make sure each file has an @CRLF as the last value)

COPY \\SEVER\LOGS\*.LOG C:\REPORTS\INVENTORY.LOG

Which will give you a single file of all machines to easily import to Excel and no file locking issues.

Works on thousands of computers within seconds.

Top
#148656 - 2005-09-28 11:31 PM Re: Hardware inventory to csv or excel file
alex1372 Offline
Lurker

Registered: 2005-09-25
Posts: 4
That's what i have:

Code:

BREAK On
$IPaddr = EnumIPinfo(0,0)
if $IPaddr = "0.0.0.0" or $IPaddr = ""
$IPinfo = GetIPinfo()
$IPaddr = $IPinfo[0]
$SNmask = $IPinfo[1]
$Gateway = $IPinfo[2]
else
$SNmask = EnumIPinfo(0,1)
$Gateway = EnumIPinfo(0,3)
endif

; Connect to specified computer
$objWMIService = GetObject( "winmgmts://./root/cimv2" )

; Query processor properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_Processor", , 48 )
; Display results
For Each $objItem in $colItems
$mycpu = ($objItem.CurrentClockSpeed) + " MHz"
Next

; Query memory properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
For Each $objItem in $colItems
$mymemory = ( ( $objItem.TotalPhysicalMemory + 1023 ) / 1024 )
Next

; Query harddisk properties
$colItems = $objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
; Display results
For Each $objItem in $colItems
; Some trickery to enable working with large numbers
$Size = $objItem.Size
$LSize = Len( $Size )
$MSize = SubStr( $Size, 1, $LSize - 3 )
$Size = ( 524288 + $MSize ) / 1048576
Next

; Header line for screen output
$myline = "@WKSTA,$IPaddr,@address,@PRODUCTTYPE @CSD,$mycpu,$mymemory,$Size,@UserID,@date"
IF Open( 3 , "Installation_Log.csv" , 5 ) = 0
$x = WriteLine( 3 , $myline + @CRLF )
ELSE
BEEP
? "failed to open file, error code : [" + @ERROR + "]"
ENDIF

Quit 0



How can i add model/chassis information to it?

Top
#148657 - 2005-09-28 11:55 PM Re: Hardware inventory to csv or excel file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
By using the appropriate WMI calls for the data you want to return. Do a search for scriptomatic and you should find a nice little utiliity for doing the scripts you want.
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
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.025 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