is it necessry to disconnect from a computer/WMI in a script before connecting to another computer?

E

emebohw

I am trying to write a script that will read through a list of
computers and verify that a connection to WMI on each can be made. In
my test I have two machines in my input file and I know one is
connectable and one is not (its off) but my script keeps reporting both
as connectable.

I am wondering if (a) I am doing something dumb or (b) need to somehow
disconnect after connecting to each host and if so how?

Heres the script I am trying to use and it works fine if theres only
one machine in the input file:

'------ start
fInputFile = "pingthing_out_pass.csv"
fPassFile = "WMIcheck_out_pass.csv"
fFailFile = "WMIcheck_out_fail.csv"
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")
Set ifile = iFSO.OpenTextFile(fInputFile)
Set ofileP = ofso.createTextFile(fPassFile, True)
Set ofileF = ofso.createTextFile(fFailFile, True)
pass = "X"

Do until ifile.AtEndOfLine

workfile = ifile.ReadLine
strcomputer = left(workfile,instr(workfile,",")-1)
'<!> next 1 commented out line(s) for debug only <!>
msgbox strcomputer
msgbox pass

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strcomputer &
"\root\cimv2")
Set colWMISettings = objWMIService.ExecQuery _
("Select * from Win32_WMISetting")
For Each objWMISetting in colWMISettings
pass = objWMISetting.BuildVersion
Next
msgbox pass
if pass <> "X" then
ofileP.WriteLine strcomputer & ", version:" & pass & ", passed WMI
test," & now()
Else
ofileF.WriteLine strcomputer & ",, failed WMI test," & now()
End if

Set objWMIService = Nothing
Set colWMISettings = Nothing
pass = "X"
Loop
'------- end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top