2012-08-03 72 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