是否可以从bat文件中清除msmq队列?
基本上我想制作一个bat文件或至少快速简单的东西,以便未经训练的员工可以在不知道任何shell或管理工具的情况下点击并修复
有人可以帮助我朝正确的方向发展吗?
答案 0 :(得分:13)
通过实用程序管理的任务包括以下内容:
不要忘记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
从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