PC Inventory Script

Started by Deana, October 02, 2013, 11:53:53 AM

Previous topic - Next topic

Deana

Pc Inventory Script: Obtains system information into HTML file and optionally displays or emails the results.
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt%2Ftsleft.web+WinBatch%2FWMI%2FUser%7ESample%7ECode+PC%7EInventory.txt

Code (winbatch) Select
;***************************************************************************
;**       PC Inventory
;**
;**
;** Purpose: Obtains system information into HTML file and optionally displays or emails the results.
;** Inputs:  SMTP server information as variables
;** Outputs: Optionally displays or emails the results.
;** System Requirements: Postie Extender. WinBatch 2010B or newer. Windows Vista or newer.
;**
;** Revisions: 2013.10.2 Deana Falk
;***************************************************************************
If Version( )< '2010B'
   Pause('Notice', 'Need 2010B or Newer Version of WinBatch')
   Exit
EndIf
ver = WinVersion( 5 )
If ver < "2-6-0"
   Pause('Notice', 'This script is designed for Windows Vista and newer.')
   Exit
EndIf

#DefineFunction udfWMIDataArray( class, properties )
   ParseData( StrReplace( properties, ',', ' ' )  )
   propcount = param0
   arrData = ArrDimension(2, propcount)
   ArrInitialize(arrData, 'NA')
   strComputer = "."
   query = "Select * from " : class
   objWMIService = GetObject("winmgmts:\\" : strComputer : "\root\cimv2")
   colItems = objWMIService.ExecQuery(query)
   instcount = colitems.Count
   instance = 1
   ForEach objItem In colItems
      If ObjectTypeGet(objItem)=="EMPTY" Then Continue
      For i=0 To param0-1
         n = i+1
         propname = param%n%
         arrData[0,i] = propname
         arrData[instance,i] = objItem.%propname%
      Next
      ; Handle multiple instances
      If instcount > instance
         ArrayRedim( arrData, ArrInfo(arrData,1)+1, -1 )
         instance = instance+1
      EndIf
   Next
   Return arrData
#EndFunction

#DefineFunction udfConvertToHTMLTable( arrData )
   rowcount = ArrInfo( arrData, 1 )
   colcount = ArrInfo( arrData, 2 )
   htmlData = '<table width="500" border="1">'
   ;Pause( rowcount, colcount)
   For row = 0 To ArrInfo( arrData, 1 ) - 1
       htmlData = htmlData : '<tr>'
       For col = 0 To ArrInfo( arrData, 2 ) - 1
          htmlData = htmlData : '<td>'
          If ObjectTypeGet( arrData[row,col] ) == 'ARRAY|VARIANT'
              data = udfArrayToList(arrData[row,col],'|')
          Else
              data = arrData[row,col]
          EndIf
          htmlData = htmlData : data
          htmlData = htmlData : '</td>'
       Next
       htmlData = htmlData : '</tr>'
   Next
   htmlData = htmlData : '</table>'
   Return htmlData
#EndFunction


#DefineFunction udfConvertToHTMLTableEx( arrData )
   ; Beautified version of the table
   rowcount = ArrInfo( arrData, 1 )
   colcount = ArrInfo( arrData, 2 )
   htmlData = '<table width="auto" border="1" cellpadding="3" cellspacing="0">'
   ;Pause( rowcount, colcount)
   For row = 0 To ArrInfo( arrData, 1 ) - 1
       ; Alternate Row Color
       If row == 0 ;Heading only
          htmlData = htmlData : '<tr bgcolor="CornflowerBlue">' ; #6495ED
       ElseIf (row mod 2) == 0      ;even numbered row
          htmlData = htmlData : '<tr bgcolor="LightGray">' ;   #D3D3D3
       Else
          htmlData = htmlData : '<tr>'
       EndIf
       For col = 0 To ArrInfo( arrData, 2 ) - 1
                    htmlData = htmlData : '<td align="left">'
          If ObjectTypeGet( arrData[row,col] ) == 'ARRAY|VARIANT'
              data = udfArrayToList(arrData[row,col],'|')
          Else
              data = arrData[row,col]
          EndIf
          htmlData = htmlData : data
          htmlData = htmlData : '</td>'
       Next
       htmlData = htmlData : '</tr>'
   Next
   htmlData = htmlData : '</table>'
   Return htmlData
#EndFunction

#DefineFunction udfArrayToList(arrData,strDelim)
   strData = ''
   count = ArrInfo ( arrData, 1 ) -1
   For ctr = 0 To count
      If ctr < count
         strData=StrCat(strData,arrData[ctr],strDelim)
      Else
         strData=StrCat(strData,arrData[ctr])
      EndIf
   Next
   Return (strData)
#EndFunction

; System Info
computername = ComputerNameGet(0)
username = Environment( 'USERNAME' )
dir = ShortCutDir( 'Personal' ,0 ,1 )

; MODIFY TO FIT YOUR NEEDS
title = 'PC Inventory'
; Email Settings
smtphost = ";mail.dadomain.com"
toaddr = "dauser@dadomain.com"
fromaddr = username : "@dadomain.com"


subject = "Hardware Info for": computername
mymsg="<html><head><title>PC INVENTORY</title></head><body><h1>":subject:"</h1>See attached.</body></html>"
flags="h"
attachment = dir: computername : ".html"




; HTML Output
fh = FileOpen( attachment, "Write")
FileWrite( fh, '<!DOCTYPE html><html><head><title>Hardware Information for computername</title><head><body><h1>':computername:'</h1>' )


heading = 'MotherBoard'
class = 'Win32_BaseBoard'
properties = 'Name,Manufacturer,Product,SerialNumber,Status'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'Battery'
class = 'Win32_Battery'
properties = 'Caption,Name,DesignVoltage,DeviceID,EstimatedChargeRemaining,EstimatedRunTime'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'BIOS'
class = 'Win32_Bios'
properties = 'Manufacturer,Name,BIOSVersion,ListOfLanguages,PrimaryBIOS,ReleaseDate,SMBIOSBIOSVersion,SMBIOSMajorVersion,SMBIOSMinorVersion'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'CDROM Drive'
class = 'Win32_CDROMDrive'
properties = 'Name,Drive,MediaLoaded,MediaType,MfrAssignedRevisionLevel'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'Computer System Product'
class = 'Win32_ComputerSystemProduct'
properties = 'Vendor,Version,Name,IdentifyingNumber,UUID'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'Computer System'
class = 'Win32_ComputerSystem'
properties = 'Name,TotalPhysicalMemory'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'CPU'
class = 'Win32_Processor'
properties = 'Name,Manufacturer,Caption,DeviceID,CurrentClockSpeed,CurrentVoltage,DataWidth,L2CacheSize,L3CacheSize,NumberOfCores,NumberOfLogicalProcessors,Status'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )


heading = 'Disk Drive'
class = 'Win32_DiskDrive'
properties = 'Model,SerialNumber,InterfaceType,Size,Partitions'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )


heading = 'IP Address'
class = 'Win32_NetworkAdapterConfiguration'
properties = 'Description,IPAddress,IPSubnet,DefaultIPGateway,DNSServerSearchOrder,WINSPrimaryServer,DNSDomain,DNSDomainSuffixSearchOrder,DHCPEnabled,DHCPServer,DHCPLeaseObtained,DHCPLeaseExpires'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )


heading = 'Network Adapters'
class = 'Win32_NetworkAdapter'
properties = 'Name,Manufacturer,Description,AdapterType,Speed,MACAddress,NetConnectionID'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )

heading = 'OS'
class = 'Win32_OperatingSystem'
properties = 'Caption,CSDVersion,FreePhysicalMemory'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )


heading = 'Physical Memory'
class = 'Win32_PhysicalMemory'
properties = 'BankLabel,DeviceLocator,Capacity,Manufacturer,PartNumber,SerialNumber,Speed'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )


heading = 'System Enclosure'
class = 'Win32_SystemEnclosure'
properties = 'Tag,AudibleAlarm,ChassisTypes,HeatGeneration,HotSwappable,InstallDate,LockPresent,PoweredOn,PartNumber,SerialNumber'
arrData = udfWMIDataArray( class, properties )
FileWrite( fh, '<h2>':heading:'</h2>' )
FileWrite( fh, udfConvertToHTMLTableEx( arrData ) )


; Finalize HTML
FileWrite( fh, '</body></html>' )
FileClose( fh )


ret = AskYesNo( title, 'Would you like to display the results?' )
If ret
   ; Display Results
   Run( attachment, '' )
EndIf

ret = AskYesNo( title, 'Would you like to EMAIL the results?' )
If ret
   ; EMAIL Results
   AddExtender("WWPST44I.DLL")
   kInit(smtphost,fromaddr,"","","")
   kDest(toaddr,"","")
   ;ret = kSendText(subject,mymsg,attachment,"h")
   ret = kSendFile(subject,attachment,attachment,flags)
   If ret == 0
      errline=kStatusInfo()
      Message("ErrLine",errline)
   EndIf
EndIf

Exit
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

The mind is everything; What you think, you become.

Deana

Looking for suggestions for any additional information that should be included in the output.....
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

I was gonna ask for the dell service tag number, but you already got it!
The mind is everything; What you think, you become.

IJRobson

I get a script error when I run this Script?

When Scanning the Processor Details it reports:
                 Ole: Unknown name for "arrData[instance,i] = objItem.L3CacheSize"

Thanks

Deana

Quote from: IJRobson on October 07, 2013, 07:43:55 AM
I get a script error when I run this Script?

When Scanning the Processor Details it reports:
                 Ole: Unknown name for "arrData[instance,i] = objItem.L3CacheSize"

Thanks

What windows platform are you running on?

On Windows Server 2003 and Windows XP:  This property is not available.: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373%28v=vs.85%29.aspx
Deana F.
Technical Support
Wilson WindowWare Inc.

IJRobson

I'm running Windows XP so that explains why it can't find the information.

IJRobson

When was ArrayRedim() added to WinBatch because I get "Uninitialized variable, undefined function, or unquoted string" on line 41?  I am currently running 2010A.

I also get errors when reading the 'SerialNumber' in the 'Win32_DiskDrive' section so I guess another Windows XP issue?

Thanks

Deana

ArrayRedim was added in 2010B. I will modify the script to check for this minimum version.
Deana F.
Technical Support
Wilson WindowWare Inc.

IJRobson