清除MSMQ队列并从bat文件重置IIS

时间:2012-08-03 09:57:33

标签: batch-file msmq

是否可以从bat文件中清除msmq队列?

基本上我想制作一个bat文件或至少快速简单的东西,以便未经训练的员工可以在不知道任何shell或管理工具的情况下点击并修复

有人可以帮助我朝正确的方向发展吗?

3 个答案:

答案 0 :(得分:13)

查看MSMQAdm Utility

通过实用程序管理的任务包括以下内容:

  • 浏览本地队列
  • 清除消息
  • 删除个别邮件
  • 停止并启动MSMQ服务
  • 连接和断开网络

不要忘记powershell,请查看PowerShell Community Extensions

<强>更新

打开powershell并逐行写入

[Reflection.Assembly]::LoadWithPartialName("System.Messaging")
$queueName = '.\Private$\testQueue'
$queue = new-object -TypeName System.Messaging.MessageQueue -ArgumentList $queueName
$queue.Purge()

从cmd调用powershell

  1. 创建txt文件。
  2. 插入所有行
  3. 更改“ps1”
  4. 上的文件扩展名

    从cmd调用脚本的最简单方法。

      

    powershell.exe -executionpolicy Unrestricted C:\ purgemsmq.ps1

答案 1 :(得分:4)

此代码有效:

[Reflection.Assembly]::LoadWithPartialName("System.Messaging") | Out-Null 
$Name=(get-wmiobject win32_computersystem).name
$QName=(
"FormatName:Direct=OS:$name\System$;DEADXACT",
"FormatName:Direct=OS:$name\System$;DEADLETTER"
)

foreach ($Q in $Qname){
$MessageQueue = New-Object System.Messaging.MessageQueue($Q)
$MSGCount=$($MessageQueue.GetMessageEnumerator2()).count

IF($MSGCount){
$MessageQueue.Purge()
Write-Host "$Q has been purged of $MSGCount messages." -ForegroundColor green
}
Else{
Write-Host "$Q is clean"}

} 

答案 2 :(得分:1)

PowerShell脚本,用于清除本地计算机上的所有专用队列:

[Reflection.Assembly]::LoadWithPartialName("System.Messaging")
$MachineName=(get-wmiobject win32_computersystem).name
[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("$MachineName") | % { $_.Purge(); }

https://stackoverflow.com/a/11793579/1235394中所述,最简单的执行方式是:

  • 将脚本保存到文件purge-private-msmq-queues.ps1
  • 在同一文件夹中创建脚本文件purge-private-msmq-queues.cmd,其中包含以下内容:

    powershell -executionpolicy Unrestricted .\purge-private-msmq-queues.ps1