Help with WMI script reading from TXT file

From: David Doumani (ddoumani_at_doumaniweb.com)
Date: 03/23/05


Date: Wed, 23 Mar 2005 13:57:20 -0500

The following script works perfectly; however is server X which is in line 8
of servers.txt is not online then strcomputer stays as the sever on line 7
an dgives me a bad result. How can I test for a machines availability
before running the script against it? For example I would like it to say
Server 888 is Unavailable for inventory collection and then have it move to
the next one.

thanks

****
'Set up your constants
Const ForReading = 1
Const HKEY_LOCAL_MACHINE = &H80000002

'Open the File System Object to Feed the Script
Set objFSO = CreateObject("Scripting.FileSystemObject")

'This line needs to be customized for the servers.txt localtion text file
Set objTextFile = objFSO.OpenTextFile ("c:\scripts\servers.txt", ForReading)

'Starts the process reading thru the input file line by line until EOF
Do Until objTextFile.AtEndOfStream
    strComputer = objTextFile.ReadLine
 Wscript.Echo ""
 Wscript.Echo "********************** Gathering Data On
**********************"
    Wscript.Echo " Computer Name From TXT File : "& strComputer
 Wscript.Echo "********************** Gathering Data On
**********************"
On Error Resume Next

' Bind to the WMI \root\cimv2
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem in colItems
    Wscript.Echo "System Name: " & objItem.SystemName
    Wscript.Echo "Processor Name: " & objItem.Name
    Wscript.Echo "Current Clock Speed: " & objItem.CurrentClockSpeed
    Wscript.Echo "Max Clock Speed: " & objItem.MaxClockSpeed
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard",,48)
For Each objItem in colItems
     Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Next

Set colItems = objWMIService.ExecQuery("Select * from
Win32_ComputerSystemProduct",,48)
For Each objItem In colItems
 Wscript.Echo "Computer Model: " & objitem.Name
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
    Wscript.Echo "Serial Number: " & objItem.SerialNumber
    Wscript.Echo "BIOSVersion: " & objItem.SMBIOSBIOSVersion
Next

Set colItems = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem",,48)
For Each objItem in colItems
    Wscript.Echo "Total Physical Memory: " & ObjItem.TotalPhysicalMemory
Next

Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
    Wscript.Echo "Operating System: " & objItem.Caption
    Wscript.Echo "Service Pack Major: " & objItem.ServicePackMajorVersion
    Wscript.Echo "Service Pack Minor: " &
objOperatingSystem.ServicePackMinorVersion
Next

Set colItems = objWMIService.ExecQuery ("SELECT * FROM
Win32_QuickFixEngineering")
 For Each objItem in colItems
 If ObjItem.HotFixID = "File 1" Then
 Wscript.Echo "Hot Fix ID: Superceded"
 else
 Wscript.Echo "Hot Fix ID: " & objItem.HotFixID
End if
Next

wscript.Echo "********* END QFE; BEGIN SOFTWARE *********"
' Software Routine;
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
strKeyPathA = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPathA, arrSubKeysA
For Each subkey In arrSubKeysA
     iRC = objReg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPathA & subkey,
"DisplayName", sValue)
     If iRC <> 0 Then
         objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPathA & subkey,
"QuietDisplayName", sValue
     End If
     If sValue <> "" Then
         Wscript.Echo sValue
     End If
Next
Loop
objTextFile.Close



Relevant Pages

  • Re: Network Script Help
    ... For Each objItem in colItems ... objItem.Manufacturer & VBCRLF ... Set colItems = objWMIService.ExecQuery("Select * from ...
    (microsoft.public.windows.server.scripting)
  • Re: Network Script Help
    ... For Each objItem in colItems ... objItem.Manufacturer & VBCRLF ... Set colItems = objWMIService.ExecQuery("Select * from ...
    (microsoft.public.windows.server.scripting)
  • Re: Network Script Help
    ... For Each objItem in colItems ... objItem.Manufacturer & VBCRLF ... Set colItems = objWMIService.ExecQuery("Select * from ...
    (microsoft.public.windows.server.scripting)
  • Re: Help with WMI script reading from TXT file
    ... Wscript.Echo " Computer Name From TXT File: "& strComputer ... For Each objItem in colItems ... Set colItems = objWMIService.ExecQuery("Select * from ...
    (microsoft.public.scripting.vbscript)
  • Still having great difficulty with error handling
    ... 'Open the File System Object to Feed the Script ... For Each objItem in colItems ... Set colItems = objWMIService.ExecQuery("Select * from ...
    (microsoft.public.scripting.vbscript)

Loading