garethEds Posted September 20, 2012 Posted September 20, 2012 I wonder if anyone has a script that will trawl the network and pick up serial numbers from any boards that are connected. Some boards do not show their serial number in the driver software so running a startup script would be an excellent way for me to do this across a large site. All I want are the following fields: Maybe it could be increased to have I have no idea how to go about this. Over to you Promethean - I'm sure it would help a lot of people as well. Gareth
OhDear Posted September 20, 2012 Posted September 20, 2012 (edited) This script should do the trick. It adds the Make, Model, Serial, MAC Address, and OS Version to the description field in Active Directory. Just save it as .VBS, you make have to delegate control so your machines can write to Active Directory.Option ExplicitOn Error Resume Next Dim objRootDSE, objNetwork, objWMIService, objComputer Dim strComputer, strMake, strModel, strSerialNumber, strMacAddresses, strMemory, intMemory Dim colBIOS, objBIOS Dim colNetworkAdapterConfiguration, objNetworkAdapterConfiguration Dim colComputerSystem, objComputerSystem Dim colPhysicalMemory, objPhysicalMemory Dim adoConnection, adoRecordset dim mydatestring dim colOperatingSystems,objOperatingSystem,osver dim oReg, lastuser, snode, spath, svaluename, svalue dim colcpu, objItem, cpuspec dim objDisk, colDisks , cspace strComputer = "." strMemory = "" strMake = "" strModel = "" strSerialNumber = "" strMacAddresses = "" myDateString = Date() Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk") For Each objDisk in colDisks If objDisk.DeviceID = "C:" Then 'Wscript.Echo "DeviceID: " & objDisk.DeviceID cspace = int(objDisk.Size/1073741824) & " GB" end if Next Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") For Each objItem in colcpu cpuspec = objItem.Name Next ' use "." for local computer sNode = "." Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE On Error Resume Next Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ & sNode & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 WScript.Echo "Could not connect to computer " & sNode Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & sNode End If End If Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems osver = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion'& " " & objOperatingSystem.Version Next If Not colComputerSystem Is Nothing Then For Each objComputerSystem In colComputerSystem strMake = objComputerSystem.Manufacturer strModel = objComputerSystem.Model Next End If Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS strSerialNumber = objBIOS.SerialNumber Next End If Set colNetworkAdapterConfiguration = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") strMacAddresses = "" If Not colNetworkAdapterConfiguration Is Nothing Then For Each objNetworkAdapterConfiguration in colNetworkAdapterConfiguration If strMacAddresses <> "" Then strMacAddresses = strMacAddresses & ", " End If strMacAddresses = strMacAddresses & objNetworkAdapterConfiguration.MACAddress Next End If Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next strMemory = (intMemory / 1024 / 1024) & " MB" End If Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" If Err.Number <> 0 Then MsgBox "Connect Error: " & Err.Description WScript.Quit End If Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) objComputer.Put "description", "Make: " & strmake & ", Model: " &strModel & ", Serial No: " & strSerialNumber & ", MAC Address: " & strMACAddresses & ", OS: " & osver objComputer.SetInfo End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If You can modify this line to remove some things reporting back like the MAC Address objComputer.Put "description", "Make: " & strmake & ", Model: " &strModel & ", Serial No: " & strSerialNumber & ", MAC Address: " & strMACAddresses & ", OS: " & osver Edited September 20, 2012 by OhDear
garethEds Posted September 21, 2012 Author Posted September 21, 2012 Giving me a syntax error in line 1 Gareth
Steve21 Posted September 21, 2012 Posted September 21, 2012 Giving me a syntax error in line 1 Gareth Option ExplicitOn Error Resume Next Should be Option Explicit On Error Resume Next Steve
garethEds Posted September 21, 2012 Author Posted September 21, 2012 A bit confused to where this saves information Help :-( Gareth
garethEds Posted September 21, 2012 Author Posted September 21, 2012 Right - I see that it writes into AD - but I don't want the machine serial numbers. I wanted the script to query the ActivBoard and grab that serial number. GJE
phillyrovers Posted September 21, 2012 Posted September 21, 2012 Hi garethedmundson, The script you are trying to create will not give you the desired results. The serial numbers that show up in the ActivDriver are not the serial numbers of the ActivBoards, but are the serial numbers of the electronics contained within the Activboard. The actual serial numbers of the Activboards are normally contained on a sticker located physically on the ActivBoard itself. Thank you
Recommended Posts