VBS script to read out message queues from multiple servers
-
17. února 2012 13:28
Hi all,
I'm fairly new to VB scripting, but thanks to this forum I got a working script to read the message queues on a server. That looks like this:
Option Explicit
Dim Locator ' As New WbemScripting.SWbemLocator
Set Locator = CreateObject("WbemScripting.SWbemLocator")Dim Service ' As SWbemServices
Set Service = Locator.ConnectServer()Dim Query ' As string
Query = "Select * From Win32_PerfRawData_MSMQ_MSMQQueue"Dim objs ' As ISWbemObjectSet
Set objs = Service.ExecQuery(Query)
if objs.Count = 0 Then
objFile.Writeline "No queues found"
Else
Dim Object ' As ISWbemObject
for each object in objs
objFile.Writeline object.MessagesInQueue & " Messages in " & object.Name
next
End ifNow I needed to run it from on server to go over multiple servers and write the results in a .txt file, with a few articles I came to this script but it gave me an error "Expected Statement":
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("output.txt", True)
Set objServerlist = objFSO.OpenTextFile("Servers.txt", 1)On Error Resume Next
Do Until objServerList.AtEndOfStreamOption Explicit
Dim Locator ' As New WbemScripting.SWbemLocator
Set Locator = CreateObject("WbemScripting.SWbemLocator")Dim Service ' As SWbemServices
Set Service = Locator.ConnectServer()Dim Query ' As string
Query = "Select * From Win32_PerfRawData_MSMQ_MSMQQueue"Dim objs ' As ISWbemObjectSet
Set objs = Service.ExecQuery(Query)
if objs.Count = 0 Then
objFile.Writeline "No queues found"
Else
Dim Object ' As ISWbemObject
for each object in objs
objFile.Writeline object.MessagesInQueue & " Messages in " & object.Name
next
End if
Next
LoopCan someone help me and guide me in the correct direction ?
Všechny reakce
-
17. února 2012 14:06
I did not check the functionality of your code. Your current problem is caused by you having a "next" and a "loop" statement at the end of the code without any matching "for" statements.
Having a "on error resume next" statement in the code makes the trouble-shooting effort much more difficult because it causes the interpreter to skip over most errors. Get rid of it!
- Označen jako odpověď Boe ProxModerator 24. února 2012 1:06