2012-08-03 75 views
8

是否可以从bat文件中清除msmq队列?清除MSMQ队列并从bat文件中重置IIS

基本上我想要一个bat文件,或者至少东西快速和容易使未经训练的员工可以点击并在不知道任何壳或管理工具

可能有人请帮助我在正确的方向解决?

回答

14

以通过该实用程序给予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. 插入的 “PS1”

从CMD最简单的方法调用脚本中的所有行

  • 更改文件扩展名。

    powershell.exe -ExecutionPolicy无限制C:\ purgemsmq.ps1

  • +0

    好吧,我会看一看。但基本上我想制作一个蝙蝠文件,或者至少快速简单一些,这样未经训练的员工就可以在不知道任何shell或管理工具的情况下点击并修复。 – Martin 2012-08-03 10:14:11

    +0

    Msmq没有命令行工具。请参阅http://stackoverflow.com/questions/9018826/msmq-command-line-in-win-7 – GSerjo 2012-08-03 10:17:12

    +0

    添加了powershell命令,只需打开powershell并逐行插入所有行 – GSerjo 2012-08-03 10:46:19

    3

    此代码:

    [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"} 
    
    } 
    
    +0

    随着代码请尝试解释一下,以及。 – Jatin 2014-03-17 19:50:24

    +0

    调用命令$ Server -scriptblock {} – IVISIONEDI 2014-09-11 23:40:14

    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