VBS Script to run agaisn't systems in a text file - McAfee Serial Number

405 Views Asked by At

Right now this VBS queries the WMI for specific details such as MAke, model, serial number. Then puts them into specific registry key locations.

right now it runs against the local machine that it runs on. How could this be updated to loop thru a text file and run against remote machines. If i wanted to take around 1000 machines from active directory put them in a text file and have the below script run against them one time

'**************************************************************
'* VBScript to create custom registry key for ePO
'* Author: 
'* Company: XXXXX
'* Usage: wscript ePO_customkeys.vbs 
'*
'* Date:        Comments
'*============================================================= 
'* 07/14/2014   Created
'* 07/15/2014   Updated variables - Stretch
'**************************************************************

On error resume next

'**************************************************************
'* Global Variables
'**************************************************************
const HOSTNAME_NAME = "."  'declar rmote computer name; use . for local PC
const HKEY_LOCAL_MACHINE = &H80000002
const REG_KEY_PATH = "SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps"



Dim objManufacturer, objModel, objSerial

'retrieve model
Set objWMIService = GetObject("winmgmts:\\" & HOSTNAME_NAME & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_ComputerSystem",,48) 

For Each objItem in colItems 
    objModel = Trim(objItem.Model)

Next

'retrieve computer manufacturer, serial
Set objWMIService = GetObject("winmgmts:\\" & HOSTNAME_NAME & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_BIOS",,48) 
For Each objItem in colItems 
objManufacturer = Trim(objItem.Manufacturer)
objSerial = Trim(objItem.SerialNumber)

Next


'add registry
'Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & HOSTNAME_NAME & "\root\default:StdRegProv")

'create registry key
oReg.CreateKey HKEY_LOCAL_MACHINE,REG_KEY_PATH

oReg.SetStringValue HKEY_LOCAL_MACHINE,REG_KEY_PATH,"CustomProps1",objManufacturer
oReg.SetStringValue HKEY_LOCAL_MACHINE,REG_KEY_PATH,"CustomProps2",objModel
oReg.SetStringValue HKEY_LOCAL_MACHINE,REG_KEY_PATH,"CustomProps3",objSerial



'**************************************************************
'* Additional debugging scripts 
'* COMMENT THEM OUT ON PRODUCTION
'**************************************************************
'WScript.Echo "Manufacturer: " & objManufacturer & ", Model: " & objModel & ", Serial: " & objSerial
'delete key
'oReg.DeleteKey HKEY_LOCAL_MACHINE, REG_KEY_PATH

WScript.Quit 
1

There are 1 best solutions below

0
On

A simple search in SO will give you the part you need. First you need to read a file and loop through it line be line.

strFilename = "C:\Temp\servers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO .OpenTextFile(strFilename)

Do Until objFile.AtEndOfStream
  ' Read a single line from the file. 
  singleHostname = objFile.ReadLine
  ProcessServer(singleHostname )
Loop

' Close the file and clean up memory
objFile.Close

Convert the greater portion of your script into a Sub called ProcessServer

Function ProcessServer(pSingleServer)
   ' Comments and proccessing....
   Set objWMIService = GetObject("winmgmts:\\" & pSingleServer& "\root\CIMV2")
   ' More comments and proccessing....
   Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & pSingleServer& "\root\default:StdRegProv")
   ' Still more comments and proccessing....
End Function

Warning

For brevity I made no effort to declare my variables or do simple error checking like file exists. Again, some simple searching can help you with those issues which i highly recommend you address.