我目前正在尝试编写一个脚本,该脚本将遍历消息队列,并在正文中存在特定字符串时删除/发送每条消息到另一个子队列。
在伪代码中我目前正在尝试实现
$queue = 'My Queue'
foreach($message in $queue)
{
if ($message.body.Contains("matchstring")
{
$message.delete OR $message.movequeue
}
}
我目前正在 powershell 中使用 [Reflection.Assembly]::LoadWithPartialName("System.Messaging"),但我不确定它是否包含我需要的所有功能。
最佳答案
您可以在 PowerShell 中执行此操作。下面是一些简单的代码,可帮助您开始并连接到队列:
$queuePath = ("Direct=OS:SERVER\private$\PRIVATEQUEUE")
$queue = New-Object System.Messaging.MessageQueue $queuePath
$queue.GetAllMessages()
使用$queue | gm 和 MSDN 帮助您到达您需要的地方。
关于powershell - 在 powershell 中一次查看 MSMQ 一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12217053/