Is it possible to purge a msmq queue from a bat file?
Essentially I want to make a bat file or at least something quick and easy so that an untrained employee can click and fix without knowing any shell or admin tools
Could someone please help me in the right direction?
Take a look on MSMQAdm Utility
Tasks administered through the utility programs include the following:
Don't forget about powershell, take a look on PowerShell Community Extensions
Update
Open powershell and write line by line
[Reflection.Assembly]::LoadWithPartialName("System.Messaging")
$queueName = '.\Private$\testQueue'
$queue = new-object -TypeName System.Messaging.MessageQueue -ArgumentList $queueName
$queue.Purge()
Call powershell from cmd
The easiest way call script from cmd.
powershell.exe -executionpolicy Unrestricted C:\purgemsmq.ps1
THis Code Works:
[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"}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With