cancel
Showing results for 
Search instead for 
Did you mean: 

Monitoring MSMQ via vbs

Wayne_Humphrey
Level 6
Partner Accredited Certified

So a while ago I wrote a simple vbs to query MSMQ as the PerfMon counters are not reliable.  There is an updated script I did some ware just need to dig it out.

Option Explicit
Dim MSMQApp ' As MsmqApplication
Set MSMQApp = CreateObject("MSMQ.MSMQApplication")

Dim strComputer

If Wscript.Arguments.Count = 0 Then
                WScript.Echo "usage: msmq.vbs server_name queue "
                WScript.Echo " "
                WScript.Echo "e.g. cscript msmq.vbs tus1ev1idxpin01 queue"
Else
                strComputer = Wscript.Arguments(0)
END If

On Error Resume Next

MSMQApp.Machine=strComputer

Dim qFormat ' As String
For each qFormat in MSMQApp.PrivateQueues
                Dim Mgmt ' As new MSMQManagement
                Set Mgmt = CreateObject("MSMQ.MSMQManagement")
                Mgmt.Init MSMQApp.Machine,,"DIRECT=OS:" & qFormat
                if Wscript.Arguments(1) <> "" then
                                if instr(qformat, Wscript.Arguments(1)) >0 then
                                                WScript.Echo qFormat & "     Messages " & CLng(Mgmt.MessageCount) & "    Size: " & int(CLng(Mgmt.BytesInQueue) / 1024) & " Kb"
                                end if
                else
                                WScript.Echo qFormat & "     Messages " & CLng(Mgmt.MessageCount) & "    Size: " & int(CLng(Mgmt.BytesInQueue) / 1024) & " Kb"
                end if
Next