VBScript, WMI, End Loop

Hello. I am working to extra event logs from the server I manage. I wrote a WMI script to do this and write it to a CSV file. My problem is, I only want the most recent 10 errors to be written. Then I want it to exit the loop and move on to the next server. Below is snippet of the script I wrote. I figured I'd exit a loop if the a counter reached 10 or so but I can't figure out how ot get out of the loop.  Anyhow, any help is appreciated.

for i = 0 to cnt 
    strComputer = arr1(i)                                       'Gets Computer Name
    objfile1.writeline "Errors For Server: " & strComputer      'Writes header to each log
    
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\root\cimv2")     'Connects to CIMV2 DB
    Set colLogFiles = objWMIService.ExecQuery ("Select * from Win32_NTEventLogFile where LogfileName='System'")                     'Queries for System Log
    
    For Each objLogFile in colLogFiles
        intTotal = objLogFile.NumberOfRecords
        objFile1.Writeline "Total Number of records for server " & strComputer & ": " & intTotal
        objFile1.Writeline "Type:, EventCode:, TimeStamp:,"
        
    Next
    
    'set i = 0
    Set colLoggedEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent Where Logfile = 'System' AND Type = 'error'")
        for each objEvent in colLoggedEvents 
            objfile1.Write objEvent.Type & ", "
            objFile1.Write objEvent.EventCode & ", "
            dtmEventDate = objEvent.TimeWritten
            strTimeWritten = WMIDateStringToDate(dtmEventDate)
            objFile1.write strTimeWritten & ", "
            objFile1.write objEvent.Message & ","
            objFile1.Writeline
            ii = ii + 1
        next
    objFile1.writeline
Next

Open in new window

mmitchell57Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mass Dot NetCommented:
"Exit For" is the command you want.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mass Dot NetCommented:
Something like this:
ii = ii + 1
If ii = 10 Then Exit For

Open in new window

0
mmitchell57Author Commented:
Really, I just dump that fright before the "next" in the for loop i'm using to write the lines?
0
mmitchell57Author Commented:
Ok, it appears the script is running, and it's not grown by mb's a second so it might be in a good direction. I'm waiting for it to finish.
0
mmitchell57Author Commented:
easy enough, it worked quite well. Thank you! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.