Receive-MsmqQueue

Does a destructive read from a queue.

Syntax

Receive-MsmqQueue
       -InputObject <MessageQueue>
       [-Transactional]
       [-RetrieveBody]
       [-Timeout <TimeSpan>]
       [-Count <Int32>]
       [<CommonParameters>]
Receive-MsmqQueue
       -InputObject <MessageQueue>
       [-Peek]
       [-RetrieveBody]
       [-Timeout <TimeSpan>]
       [-Count <Int32>]
       [<CommonParameters>]

Description

The Receive-MsmqQueue cmdlet does a destructive read from a queue. The cmdlet returns the received System.Messaging.Message object. This cmdlet accepts values for the Name parameter of path names, format names, and direct format names. Some other Message Queuing (also known as MSMQ) cmdlets require a friendly name for the queue. If you specify the Peek parameter, the cmdlet peeks at the message instead of doing a destructive read. The cmdlet succeeds if it returns at least one message.

If you specify the Peek parameter, this cmdlet returns the number of messages that is the minimum of the number supplied by the Count parameter and the number of messages in the queue.

Examples

Example 1: Perform a transacted read

PS C:\> Get-MsmqQueue -Name "a04bm10\private$\order_queue" | Receive-MsmqQueue -Transactional

This command gets the specified queue by using the Get-MsmqQueue cmdlet. The command passes the result to the current cmdlet by using the pipeline operator. The current cmdlet performs a transacted read on the queue.

Parameters

-Count

Specifies the number of messages to be returned. The default value is 1. You must specify a value larger than 0.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InputObject

Specifies a MessageQueue object. The cmdlet reads from the queue that the MessageQueue specifies. This parameter accepts pipeline input.

Type:MessageQueue
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Peek

Indicates that this cmdlet returns a copy of the first message in the queue without removing the message from the queue.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-RetrieveBody

Indicates that this cmdlet returns the body of the message.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Timeout

Specifies the maximum time, in milliseconds, to wait for the queue to contain a message. The default value is 0.

Type:TimeSpan
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Transactional

Indicates that the cmdlet performs a transacted receive.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.Msmq.PowerShell.Commands.MessageQueue

Outputs

Object