Inventory computer serial numbers during logon

Filed Under (Windows Networking) by Just An Admin on 23-05-2008

Why did we write this script? IBM allows us to get the warranty status of our IBM systems and how long the warranty lasts. It also enables us to check if the extended warranty was registered correctly.

Lookup for a single system
Lookup for multiple systems



The compilation of a list or input file that contains the required fields for a ‘multiple systems lookup’ wasn’t as easy to do as we had hoped.

Below you will find code to a script that writes the model, type and serial number with additional information, such as user name and computer name, to a file on one of your server, in the correct layout. Each inventory is written to a separate file, so that you can quickly see the last update time/date per system. Merge (Command prompt: copy \folder\*.txt merged.txt) all the files together to compile a checklist. Rename the merged.txt file to merged.csv and open it with Excel. Remove the first column and you have a .csv file for the ‘multiple systems lookup’.

You can run this script manually or run it from a Windows network policy or logon script.

Copy and paste the code below in a VBS file (whoareyou.vbs) and change the bold part.

[cc width=”600″ lang=”vb”]

Dim objfso, objWMIService, objItem, colItems
Dim strPath, strFile, strComputer

strComputer = “.”
Set WshShell = WScript.CreateObject(“WScript.Shell”)
Set WshSysEnv =WshShell.Environment(“PROCESS”)

Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colSettings = objWMIService.ExecQuery (“Select * from Win32_OperatingSystem”)
For Each objOperatingSystem in colSettings
Next

Set colSettings = objWMIService.ExecQuery (“Select * from Win32_ComputerSystem”)
For Each objComputer in colSettings
strPath = “\\myserver\storagefolder\” & objComputer.Name & “_” & (WshSysEnv(“USERNAME”)) & “.txt”
next

Set objfso = CreateObject(“Scripting.FileSystemObject”)
Set strFile = objfso.CreateTextFile(strPath, True)
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colSettings = objWMIService.ExecQuery (“Select * from Win32_OperatingSystem”)
For Each objOperatingSystem in colSettings
Next

Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colBIOS = objWMIService.ExecQuery (“Select * from Win32_BIOS”)
For each objBIOS in colBIOS
Set colSettings = objWMIService.ExecQuery (“Select * from Win32_ComputerSystem”)
For Each objComputer in colSettings
strFile.WriteLine(objComputer.Manufacturer & “, ” & objComputer.Model & “, ” & objBIOS.SerialNumber & “, workstation name: ” & objComputer.Name & “, username: ” & (WshSysEnv(“USERNAME”)))
Next
Next

strFile.Close
Wscript.Quit

[/cc]

Post a comment