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=objfspenTextFile("\\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
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=objfspenTextFile("\\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