Hello,
I am fairly new to programming in VbScript and using WMI. I have a program that reads hostnames from a txt file, it scans the network for the hostname and then it displays the hostname and its respective Windows Operating system (CAPTION).
I am trying to get all Windows XP machines upgraded to Windows 7. I am trying to run this list to give me an idea of how many machines that I have upgraded and an idea of how many I still have to upgrade, etc.
The problem is that when I use the statement “On Error Resume Next”…if the script tries to contact a hostname which is a BAD HOST or if the hostname is DOWN it displays the operating system from the last hostname. Then each and every name that is scans moving forward all shows that same operating system.
Please take a look at this code and tell me what maybe causing the problem. If there is a better way to write the code…I would appreciate any help you can give.
BH
_________
On Error Resume Next
const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile= objFSO.OpenTextFile _
("C:\users\bhowerton\desktop\hostnames.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.close
arrComputers = Split(strText, vbCrlf)
for Each strComputer in arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
Wscript.Echo strComputer & ": " & objOperatingSystem.Caption
Next
Next
I am fairly new to programming in VbScript and using WMI. I have a program that reads hostnames from a txt file, it scans the network for the hostname and then it displays the hostname and its respective Windows Operating system (CAPTION).
I am trying to get all Windows XP machines upgraded to Windows 7. I am trying to run this list to give me an idea of how many machines that I have upgraded and an idea of how many I still have to upgrade, etc.
The problem is that when I use the statement “On Error Resume Next”…if the script tries to contact a hostname which is a BAD HOST or if the hostname is DOWN it displays the operating system from the last hostname. Then each and every name that is scans moving forward all shows that same operating system.
Please take a look at this code and tell me what maybe causing the problem. If there is a better way to write the code…I would appreciate any help you can give.
BH
_________
On Error Resume Next
const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile= objFSO.OpenTextFile _
("C:\users\bhowerton\desktop\hostnames.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.close
arrComputers = Split(strText, vbCrlf)
for Each strComputer in arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
Wscript.Echo strComputer & ": " & objOperatingSystem.Caption
Next
Next