powershell - 在 powershell 中一次查看 MSMQ 一条消息

标签 powershell msmq

我目前正在尝试编写一个脚本,该脚本将遍历消息队列,并在正文中存在特定字符串时删除/发送每条消息到另一个子队列。

在伪代码中我目前正在尝试实现

$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/

相关文章:

powershell - 与对象的属性进行比较时,Get-ADUser -Filter 失败

git - 已签名的 powershell 脚本未在源代码管理后签名

performance - RabbitMQ 与 MSMQ 的比较

c# - MSMQ 导致 Windows 8 崩溃并出现蓝屏死机

powershell - 如何在 Powershell 中对多个变量进行逻辑或运算

windows - powershell windows 形成浏览对话框

c# - 需要帮助来决定什么是跟踪系统 (.NET) 的最佳解决方案

c# - 涉及 EntityFramework/SQL Server 和 NServiceBus/MSMQ 的分布式事务中的非同时提交

node.js - 使用 Node.js 和 MSMQ 的最佳方式是什么?

powershell - 为其他登录用户打开交互式 PowerShell GUI 脚本