Page 1 of 2 12>
Topic Options
#192471 - 2009-02-24 02:45 PM Hardware inventory
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
Hi guys,

I am after a script which tells me the following on each users system :-

- logged on users
- make/model/serial number of users system

I also want this info to be written to a file. Please assist.

Many thanks

Saj.

Top
#192472 - 2009-02-24 02:59 PM Re: Hardware inventory [Re: Saj]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
search the forums.
lots of examples.
specially the compinfo scripts.
_________________________
!

download KiXnet

Top
#192473 - 2009-02-24 03:17 PM Re: Hardware inventory [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
The WMISysInfo() UDF gathers a fair amount of info from a local or remote system. It returns an array, which, combined with the CSV() UDF can create a file ready to import into Excel or a database.

I think its posted here, but the latest versions are always on my web site in the Resources section.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192478 - 2009-02-24 04:15 PM Re: Hardware inventory [Re: Glenn Barnas]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
I am new kixtart, have got a copy of your WMISysInfo script. Do I need to put in a host name anywhere to run this script?
Top
#192483 - 2009-02-24 05:01 PM Re: Hardware inventory [Re: Saj]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
The WMISysinfo script produces alot of info, is there anyway I can just run a simple script to get the info that I have requested above ?

Thanks

Saj

Top
#192484 - 2009-02-24 05:06 PM Re: Hardware inventory [Re: Saj]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
You can use it as is and only employ the data you need, or use it as a basis for writing your own script.

As Lonk mentioned, there are many inventory script fragments here that you can modify or build into your own tool.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192488 - 2009-02-24 05:43 PM Re: Hardware inventory [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
An example of a script that gets the info you want.
Work great on my Dell laptop.

 Code:
$wmiColl1 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_ComputerSystem ")
$wmiColl2 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_BIOS ")

For Each $wmiObj in $wmiColl1
	? "Manufacturer: " $wmiObj.Manufacturer
	? "Model: " $wmiObj.Model
	? "Currently logged on user: " $wmiObj.UserName
Next

For Each $wmiObj in $wmiColl2
	? "Service tag:" Trim($wmiObj.SerialNumber)
Next

Sleep 3
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#192509 - 2009-02-25 10:31 AM Re: Hardware inventory [Re: Mart]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
Thanks for that script Mart. That's exactly what I need. I just need the results to be stored in a text file or DB. Can you tell me how I can do that or provide the script.

Many thanks

Saj

Top
#192510 - 2009-02-25 10:43 AM Re: Hardware inventory [Re: Saj]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hey I cannot give everything on a silver platter. You learn it by doing it so have a look at the Open, WriteLine and Close functions in the manual.
If you are new to Kix than writing it to a DB might be a huge step to start with. Writing it to a text file is imho the first step. If you are more familiar with kix then start doing DB stuff.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#192512 - 2009-02-25 11:30 AM Re: Hardware inventory [Re: Mart]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
Am using the following command

RedirectOutput("hardware.log") = 0
ENDIF

But then it just creates a hardware.log file with this in it
Opened 'hardware.log' at 10:17:42

I need the screen output to go to this log file preferable with the users name as the filename.

Any help appreciated.

Top
#192514 - 2009-02-25 11:40 AM Re: Hardware inventory [Re: Saj]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what is this endif?

if you want all screen output in there, obviously you put this line before any output.

if you want the username in the filename, why don't you put it there?
look in the manual for @userid
_________________________
!

download KiXnet

Top
#192516 - 2009-02-25 12:00 PM Re: Hardware inventory [Re: Lonkero]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
This is the script that I am using :-

RedirectOutput("hardware.txt") = 0

$wmiColl1 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_ComputerSystem ")
$wmiColl2 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_BIOS ")

For Each $wmiObj in $wmiColl1
? "Manufacturer: " $wmiObj.Manufacturer
? "Model: " $wmiObj.Model
? "Currently logged on user: " $wmiObj.UserName
Next

For Each $wmiObj in $wmiColl2
? "Service tag:" Trim($wmiObj.SerialNumber)
Next

Sleep 3

Is this ok ?

Top
#192517 - 2009-02-25 01:32 PM Re: Hardware inventory [Re: Saj]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Ok, one more silver platter \:\)

Personally I do not like RedirectOutput so much.
I’d go for the Open, Writeline, Close option.

 Code:
Break on

$rc = Open(1, @SCRIPTDIR + "\hardware.txt", 5)

$wmiColl1 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_ComputerSystem ")
$wmiColl2 = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_BIOS ")

For Each $wmiObj in $wmiColl1
	$rc = WriteLine(1, "Manufacturer: " + $wmiObj.Manufacturer + @CRLF)
	$rc = WriteLine(1, "Model: " + $wmiObj.Model + @CRLF )
	$rc = WriteLine(1, "Currently logged on user: " + $wmiObj.UserName + @CRLF )
Next

For Each $wmiObj in $wmiColl2
	$rc = WriteLine(1, "Service tag:" + Trim($wmiObj.SerialNumber) + @CRLF)
Next

$rc = Close(1)


This will give you issues when the next pc is writing to the file because you will not know who wrote what. Adding the system name would fix that or even create separate files for each computer. If this runs during logon the separate files option would be best imho because it will prevent issues with the file being locked for writing by system1 when system2 want to write his data.


Edited by Mart (2009-02-25 01:35 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#192518 - 2009-02-25 01:58 PM Re: Hardware inventory [Re: Mart]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
Thanks Mart, your a star.

One more thing the script creates the file, but the logged on username does not show up, it's blank. This script will run upon logon, so ideally I want a separate file for each person who logs on with this info and the name of the file must be the users name.

Cheers

Top
#192520 - 2009-02-25 02:36 PM Re: Hardware inventory [Re: Saj]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
I guess the logged on name is not yet known to WMI so it returns empty. Nothing you can do about that besides letting it write @USERID and not pulling it out with WMI.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#192521 - 2009-02-25 02:37 PM Re: Hardware inventory [Re: Saj]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Then you change the line that opens the file

$rc = Open(1, @SCRIPTDIR + "\hardware.txt", 5)

Becomes

$rc = Open(1, "\\server\share\" + @UserID + ".txt", 5)

Or if you are not going to clean up the files on a regular basis...

$rc = Open(1, "\\server\share\" + @UserID + Join(Split(@Date,"/")) + ".txt", 5)
_________________________
Today is the tomorrow you worried about yesterday.

Top
#192524 - 2009-02-25 03:31 PM Re: Hardware inventory [Re: Gargoyle]
Saj Offline
Fresh Scripter

Registered: 2009-02-24
Posts: 8
Loc: United Kingdom
Thanks Gargoyle. That works a treat.
Top
#192525 - 2009-02-25 03:43 PM Re: Hardware inventory [Re: Saj]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
darn golden platter'ers'
_________________________
!

download KiXnet

Top
#192527 - 2009-02-25 08:45 PM Re: Hardware inventory [Re: Lonkero]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
 Code:
break on
$ = setoption('wrapateol','on')
$ = SETCONSOLE("hide")

$InvVer = '2009/01/14 - VPN Subnet reporting'

$start = @ticks

	$Make 	=Trim(Split(WMIQuery("Manufacturer","Win32_ComputerSystem"))[0])
	$Model	=trim(WMIQuery("Model","Win32_ComputerSystem"))
	$SerNo	=WMIQuery("SerialNumber","Win32_BIOS")
		If Len($SerNo) < 2 	
			$SerNo=WMIQuery("SerialNumber","Win32_SystemEnclosure")
			If InStr($serno,"|")
				For Each $Return in Split($serno,"|")
					If Len($Return)<10	$serno=$Return		EndIf
					Next
				EndIf
			EndIf
	$SerNo	=Trim(Ucase($SerNo))
	if $serNo < '1'		quit		endif

	$asset	=WMIQuery("SMBIOSAssetTag","Win32_SystemEnclosure")
	if instr($asset,"|")
		for each $return in split($asset,"|")
			if $return	$asset=$return		endif
		next
	endif

	$asset	= join(Split($asset,"|"),'')
	$asset	= Trim(Ucase($asset))

	$CPUsp	=WMIQuery("CurrentClockSpeed","Win32_Processor")
		Select
			case left($CPUsp,3) = "339"		$CPUsp=3400
			case left($CPUsp,3) = "319"		$CPUsp=3200
			case left($CPUsp,3) = "299"  		$CPUsp=3000
			case left($CPUsp,3) = "279"		$CPUsp=2800
			case left($CPUsp,3) = "269"		$CPUsp=2600
			case left($CPUsp,3) = "239"		$CPUsp=2400
			case left($CPUsp,3) = "229"		$CPUsp=2200
			case left($CPUsp,3) = "220"		$CPUsp=2200
			case left($CPUsp,3) = "199"		$CPUsp=2000
   			case left($CPUsp,3) = "186"  		$CPUsp=1860
   			case left($CPUsp,3) = "182"  		$CPUsp=1830
			case left($CPUsp,3) = "179"		$CPUsp=1800
			case left($CPUsp,3) = "169"		$CPUsp=1700
			case left($CPUsp,3) = "159"		$CPUsp=1600
			case left($CPUsp,3) = "139"		$CPUsp=1400
			case left($CPUsp,3) = "106"		$CPUsp=1100
			case left($CPUsp,2) = "99"		$CPUsp=1000
			case left($CPUsp,2) = "90"		$CPUsp=900
			case left($CPUsp,2) = "85"		$CPUsp=850
			case left($CPUsp,2) = "70"		$CPUsp=700
			case left($CPUsp,2) = "66"		$CPUsp=667
			case left($CPUsp,2) = "59"		$CPUsp=600
			case left($CPUsp,2) = "49"		$CPUsp=500
			case left($CPUsp,2) = "39"		$CPUsp=400
			EndSelect

	$dimms	=Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|")
		For $a=0 to Ubound($dimms)
			$=Execute("$$dimm$a=val($$dimms[$a]) / 1048576")
			$=Execute("$$memory=val($$Memory)+val($$dimm$a)")
		Next

	$nic=0
	Do
		$ip 	= EnumIPInfo($nic,0)
		$snm	= EnumIPInfo($nic,1)
		$NicDesc= EnumIPInfo($nic,2)
		$mygw	= EnumIPInfo($nic,3)
		$nic=Val($nic)+1
	Until instr($ip,'192.168.22.') OR instr($ip,'192.168.24') OR instr($ip,'192.168.201.') OR Val($nic) > 10
	
	$network = left($ip,instrrev($ip,'.'))

	$Mac	=WMIQuery("MACAddress","Win32_NetworkAdapterConfiguration",,"Description",$NicDesc)
	$Mac	=Join(Split($mac,':'),'')
	$Mac	=Left($mac,InStr($mac,'|')-1)

	$NAITVD      ="HKLM\Software\Network Associates\TVD"
	$vsengine    =$NAITVD+"\Shared Components\VirusScan Engine\4.0.xx"
	$virusScan   =$NAITVD+'\VirusScan'+ iif(keyexist($NAITVD+'\VirusScan Enterprise\CurrentVersion'),' Enterprise\CurrentVersion','')
	$vscandir    =readvalue($virusScan,"szInstallDir")
	$vscaneng    =readvalue($vsengine,"szEngineVer")
	$vsdatdir    =readvalue($vsengine,"szInstallDir")
	$McAfee	     ="HKLM\Software\McAfee"
	if KeyExist($McAfee)
		$avengine    =$McAfee+"\AVEngine"
		$avDP	     =$McAfee+"\DesktopProtection"
		$vscanver    =readvalue($avDP,"szProductVer")
		$vscaneng    =readvalue($avengine,"EngineVersionMajor") + "." + readvalue($avengine,"EngineVersionMinor")
		$vscandat    =readvalue($avengine,"AVDatVersion")
		$vsdatdate   =readvalue($avengine,"AVDatDate")
	else if instr($virusScan,'Enterprise')  
		$vscanver    =readvalue($virusScan,"szProductVer")
		$vscandat    =readvalue($vsengine,"szVirDefVer")
		$vsdatdate   =readvalue($vsengine,"szVirDefDate")
		else
			$vscanver    =readvalue($virusScan,"szCurrentVersionNumber")
			$vscandat    =readvalue($vsengine,"szDatVersion")
			$vsdatdate   =readvalue($vsengine,"szDatDate")
		endif
	endif

	$MSOdir	=readvalue("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe","Path")
	$excel	=getfileversion("$MSOdir\excel.exe")
	$MSOVer =split($excel,'.')[0]

	$MSOSPVer = ''

	$assigned = readvalue("HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters","srvcomment")
	if left($assigned,2) = '68'
		$assigned = left(right(join(split(join(split($assigned,' '),''),'-'),''),-2),9)
	endif

	$ini = 0

$cnstring = "DRIVER={SQL Server};SERVER=inventory;UID=Inventory;PWD=kixscript;DATABASE=inv"

$cn = CreateObject("ADODB.Connection")
$cmd= CreateObject("ADODB.Command")
$rs = CreateObject("ADODB.RecordSet")

$cn.connectionstring = $cnstring
$cn.open
$cmd.activeconnection = $cn
$rs.cursortype = 3
$rs.locktype = 3
$rs.activecommand = $cmd

$cmdtxt = "select * from tbl_Main where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	IF $rs.eof = -1		$rs.addnew	ENDIF 

	$rs.fields.item("SerialNumber").value  = $serNo
	$rs.fields.item("ComputerName").value  = @wksta
	$rs.fields.item("AssignedTo").value    = $assigned
	$rs.fields.item("NetworkID").value     = $network
	$rs.fields.item("IPAddress").value     = $ip
	$rs.fields.item("InvDate").value       = @date
	$rs.fields.item("Version").value       = $InvVer
$rs.update							;? 'Error = '+@ERROR+' - '+@SERROR
;if not @error
	$nul = WriteValue('HKLM\SOFTWARE\Information Technology\SQLInventory','LastRun',@date,REG_SZ)
;endif
$rs.close

$cmdtxt = "select * from dbo._tbl_OSEnv where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	IF $rs.eof = -1		$rs.addnew	ENDIF 

	$rs.fields.item("SerialNumber").value	= $serNo
	$rs.fields.item("OS").value 		= @ProductType
	$rs.fields.item("OSCSD").value		= @csd
	$rs.fields.item("64bit").value		= @OnWoW64
	$rs.fields.item("AVEngine").value	= $vscanver
	$rs.fields.item("AVDate").value		= $vsdatdate
	$rs.fields.item("MSO").value		= $MSOVer
	$rs.fields.item("MSOSP").value		= $MSOSPVer
$rs.update							? 'Error = '+@ERROR+' - '+@SERROR
$rs.close



$cmdtxt = "select * from dbo._tbl_OrgCodes where OrgCode = '$Asset'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	$code = IIF($rs.eof = -1,1,0)
$rs.close							;? 'Error = '+@ERROR+' - '+@SERROR



$cmdtxt = "select * from tbl_Computers where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR
	IF $rs.eof = -1
		$rs.addnew 

		$rs.fields.item("SerialNumber").value	= $serNo
		if $code = 1
			$rs.fields.item("Tag").value= $asset	
		else
			$rs.fields.item("OrgCode").value= $asset
		endif
		$rs.fields.item("Make").value		= $Make 	
		$rs.fields.item("Model").value		= $Model	
		$rs.fields.item("CPU").value		= $CPUsp
		$rs.fields.item("Memory").value		= $memory
		$rs.fields.item("FirstInventory").value = @date
		$rs.update					;? 'Error = '+@ERROR+' - '+@SERROR
		;if not @error
			$nul = WriteValue('HKLM\SOFTWARE\Information Technology\SQLInventory','FirstRun',@date,REG_SZ)
		;endif
	else
		if $rs.fields.item("Tag").value < '0' and $code = 1
			$rs.fields.item("Tag").value= $asset	
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		endif

		if $rs.fields.item("OrgCode").value < '0' and $code = 0
			$rs.fields.item("OrgCode").value= $asset
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		endif

		if $rs.fields.item("FirstInventory").value < '0'
			$rs.fields.item("FirstInventory").value = @date
			$rs.update				;? 'Error = '+@ERROR+' - '+@SERROR
		endif
	ENDIF
$rs.close




$cmdtxt = "Delete from dbo._tbl_Software where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt 
$rs.Open($cmd) 			;? 'Error = '+@ERROR+' - '+@SERROR
$rs.close 			;? 'Error = '+@ERROR+' - '+@SERROR

$cmdtxt = "select * from dbo._tbl_Software where SerialNumber = '$serNo'"
$cmd.commandtext = $cmdtxt $rs.open ($cmd)			;? 'Error = '+@ERROR+' - '+@SERROR

$Index = 0	$err = 0	$key = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Do
	$SubKey = ENUMKEY($Key, $Index)
	If @ERROR = 0
		if not left($subkey,'2') = 'KB'
			$DisplayName 	= Readvalue($key+$subKey,'DisplayName')
			$DisplayVersion = Readvalue($key+$subKey,'DisplayVersion')
			$InstallDate 	= Readvalue($key+$subKey,'InstallDate')
			$InstallLocation= Readvalue($key+$subKey,'InstallLocation')
			$Publisher 	= Readvalue($key+$subKey,'Publisher')

			if not $DisplayName + $DisplayVersion + $InstallDate + $InstallLocation + $Publisher < 'a'	
				$rs.addnew
				$rs.fields.item("SerialNumber").value		= $Serno 
				$rs.fields.item("RegKeyName").value		= $SubKey 
				$rs.fields.item("DisplayName").value		= $DisplayName	
				$rs.fields.item("DisplayVersion").value		= $DisplayVersion	
				$rs.fields.item("InstallDate").value		= $InstallDate
				$rs.fields.item("InstallLocation").value 	= $InstallLocation
				$rs.fields.item("Publisher").value		= $Publisher
				$rs.fields.item("InvDate").value      		= @date
				$rs.update
			endif
		endif
		$Index = $Index + 1
	else
		$err = 1
	Endif
Until $err

$rs.close



Edited by Radimus (2009-02-25 10:45 PM)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#192546 - 2009-02-26 03:17 AM Re: Hardware inventory [Re: Radimus]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
As I live an breath. Was that a post from Radimus?

Cheers Rad and glad you're still around somewhere.

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.049 seconds in which 0.017 seconds were spent on a total of 14 queries. Zlib compression enabled.

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