【问题标题】:Purge MSMQ queue and reset IIS from a bat file清除 MSMQ 队列并从 bat 文件中重置 IIS
【发布时间】:2012-08-01 08:49:17
【问题描述】:

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

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

有人可以帮助我朝正确的方向前进吗?

【问题讨论】:

    标签: batch-file msmq


    【解决方案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
      

    【讨论】:

      【解决方案2】:

      看看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”上的文件扩展名

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

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

      【讨论】:

      • 好的,我去看看。但本质上,我想制作一个 bat 文件,或者至少是一些快速简单的东西,以便未经培训的员工可以在不知道任何 shell 或管理工具的情况下单击并修复。
      • 添加了powershell命令,打开powershell逐行插入
      • 谢谢!这可以以任何方式自动化吗?
      • 让我们开始吧。 1)创建txt文件。 2) 插入所有行 3) 更改“ps1”上的文件扩展名。 4)从cmd调用脚本的最简单方法。 powershell.exe -executionpolicy 不受限制的 C:\purgemsmq.ps1
      【解决方案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"}
      
      } 
      

      【讨论】:

      • 请连同代码一起尝试解释一下。
      猜你喜欢
      • 2010-12-06
      • 2011-06-16
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 2017-08-15
      • 2010-11-06
      • 2015-06-13
      相关资源
      最近更新 更多