How to count MSMQ messages in private queue by Scribe label with PowerShell

574 views Asked by At

I have Scribe Insight server which uses three private queues (scribedeadmessage, scribein and scriberetry). I know how to count number of messages in each queue with PowerShell, but I would like to count number of messages by message label in each queue with PowerShell.

Message structure from Scribe publisher looks like;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CustomerAddress
  ScribePublishDate="2017-01-06T05:39:13.6212008+01:00"
  ScribeLabel="CustomerAddress"
  MessageLabel="CustomerAddress">

How can I count how many messages with ScribeLabel="CustomerAddress", "CustomerRelation", etc. are curently in scribein queue?

2

There are 2 answers

1
Prasoon Karunan V On

I hope you need to use XML objects here.

an Example code , say we have an XML named test.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ParentTag
  ChildOne="2017-01-06T05:39:13.6212008+01:00"
  ChildTwo="Value1"
  ChildThree="Value2">
</ParentTag>

[XML]$XML = Get-Content -path .\test.xml

$XML.SelectNodes("//ParentTag[@ChildTwo='Value1']")

above line of code will filter ParentTag only if ChildTwo equals 'Value1'

Hope this gives you a hint

Reagrds,

kvprasoon

0
Stephen Turner On

The label is available directly from the MSMQ object so you shouldn't need to look at the XML. Then if you use the Group-By cmdlet you will get the count in the results.

[Reflection.Assembly]::LoadWithPartialName("System.Messaging")
write-host

$Queue = ".\private$\scribein"

(new-object System.Messaging.MessageQueue($Queue)).GetAllMessages() `
    | Group-Object -Property label `
    | Sort-Object -Property Count -Descending `
    | foreach -Process { write-host  $_.Count, $_.Name }

write-host
Read-Host -Prompt "Press Enter to continue"