Get-MSMQOutgoingQueue

Hi,
I am running this command PS C:> Get-MsmqOutgoingQueue -Name “Order*” | Clear-MsmqOutgoingQueue To clear Outgoing queue.
I want to clear only those queue that have a state MQ_QUEUE_STATE_NONACTIVE or MQ_QUEUE_STATE_WAITING.
The output of Get-MsmqOutgoingQueue is:
DestinationQueueFormatName : DIRECT=OS:Maasw53.cloudsfer.com\private$\MaaS.Backend.Planner.3
MessageCount : 5
BytesInQueue : 12700
UnacknowledgedMessageCount : 0
UnprocessedMessageCount : 0
ConnectionHost : maasw51
NextHops :
Transactional : MQ_XACT_STATUS_UNKNOWN
Foreign : STATUS_UNKNOWN
EodFirstNonAck : System.__ComObject
EodLastNonAck : SeqID: 6963899006397186076 SeqNo: 0 PrevNo: 0
EodLastAck : SeqID: 6963899006397186076 SeqNo: 8909 PrevNo: 0
EodNextSeq : SeqID: 6963899006397186076 SeqNo: 8915 PrevNo: 8914
EodLastAckCount : 1
EodLastAckTime :
EodNoAckCount : 0
EodNoReadCount : 0
EodResendCount : 1
EodResendInterval : 30000
EodResendTime :
State : MQ_QUEUE_STATE_NONACTIVE
Who do I modify the script?

Thanks

Hi, welcome to the forum :wave:

Please edit your post using the </> button to format your code properly. This makes it much easier for people to read and to copy/paste for testing.

I can’t test this but as the cmdlet doesn’t provide any way to filter it sounds like a job for Where-Object

Get-Help Where-Object

Get-MsmqOutgoingQueue -Name "Order*" | Where-Object {$_.State -eq 'MQ_QUEUE_STATE_NONACTIVE' -or $_.State -eq 'MQ_QUEUE_STATE_WAITING' | Clear-MsmqOutgoingQueue
1 Like

Thanks, The command works.