Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ping each workstation first, then check WS Memory totals using WMI

Status
Not open for further replies.

Pyro777

MIS
Jul 14, 2006
47
0
0
US
I need a little help with my syntax....
This script displays the memory information from all of my systems when it is completed, I am trying to ping the systems first before letting the script search the WMI to query the memory information, if the system does not respond, I want it to log that WS#XXXX is not reachable, then loop back to the top to check the next system on my list...

What happens is the script runs fine when checking the WMI, but if there is a system that does not respond to a PING, it will use the previous information written for that system..

I know its something small that I am missing, any help would be much appreciated !!!


On Error Resume Next

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim objshell, fso, f, objwmi, mydatetime, strcomputer, objwmiservice, colItems, objitem, SystemName
Dim colsettings, colsettingsBios, strmodel, objcomputer, objDictionary, objFSO, objTextFile, i
Dim strNextLine, WSHShell, WshNetwork, objLogFile, objFile, objwmis
Dim colCSItems, objCSItem, colOSItems, objOSItem, colComputer,strLogonUser
Dim objSWbemServices, colSWbemObjectSet, report, strcmd, strTemp
Set WSHShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objshell = WScript.CreateObject ("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("\\SERVER\common\scriptlogs\laptop.txt", ForReading)

MyDateTime = Month(Date) & "-" & Right ("0" & Day(Date), 2) & "-" & Right("0" & Year(Date), 2)
report="LaptopMemory1"

i = 0


Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine

strcomputer = strNextLine

If Reachable (strcomputer) Then


Else Do
F.WriteLine "The Laptop" & strcomputer & " was not found !!"
F.WriteLine " "
X = 3
F.WriteLine " "
f.Close

i = i + 1
Loop
End If


strCmd = "ping -n 1 " & strcomputer
Set objExec = objShell.Exec(strCmd)
strTemp = UCase(objExec.StdOut.ReadAll)

If InStr(strTemp, "REPLY FROM") Then
Reachable = True
Else
Reachable = False
End If




Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
Set F=objfso_OpenTextFile("\\SERVER\users\reports\"& report &"-" & mydatetime & ".txt",ForAppending,True)

F.WriteLine "Your Workstation number is: " & strcomputer


F.WriteLine " "

F.WriteLine "INSTALLED MEMORY DIMM INFORMATION"
Set objwmi = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem")
For Each objComputer In colsettings
strmodel = CStr(objComputer.Model)

F.WriteLine "Your Model number is: " & objComputer.Model

Next


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
For Each objitem In colItems

F.WriteLine "Memory Stick Location: " & objItem.DeviceLocator
F.WriteLine "Memory Capacity is: " & Int(objItem.Capacity /1024/1024)
F.WriteLine "The Memory speed is: " & objItem.Speed
F.WriteLine " "
Next

Set objSWbemServices = GetObject("winmgmts:\\" & strComputer)
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

For Each objSWbemObject In colSWbemObjectSet
F.WriteLine "Total Physical Memory (kb): " & Int(objSWbemObject.TotalPhysicalMemory /1024)
Next
F.WriteLine " "
f.Close

i = i + 1
Loop
 
Plenty of syntax errors in your code.
Could you, please, post your real code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That is the code i am using, I added the Ping information but not sure if it that part is actually working... If I take it out, I takes over 20 mins for 15 systems to be checked as the script stalls on workstations that are not available on my network...
 
Comment out the On Error Resume Next instruction and discover the mess.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top