Accessing MSMQ via PowerShell

11,668

Solution 1

If you click up one level in the link you provided you'll see that you're looking at pre-release PowerShell 4.0 module documentation. Here's the link to the parent page.

https://web.archive.org/web/20131029215718/http://technet.microsoft.com/en-us/library/dn249523.aspx

PowerShell Community Extensions (PSCX) has some cmdlets for working with MSMQ, and it works with PowerShell 2.0, though.

Solution 2

The below method works in Powershell 2.0:

$query = "SELECT MessagesinQueue FROM Win32_PerfRawData_MSMQ_MSMQQueue WHERE Name = 'myPrivateQueueName'"
$wmiObject = Get-WmiObject -Query $query
$wmiObject.MessagesinQueue

You can list the queues with this query:

$query = "SELECT * FROM Win32_PerfRawData_MSMQ_MSMQQueue"

Look at the __PATH property which will end in .Name="theQueueName"

Share:
11,668
Richard
Author by

Richard

Need a powershell script creating or editing? Email: [email protected] for more info. I'm great at developing small and large PowerShell automation projects/scripts. I have developed many scripts for many companies, with my specialties being in automation of: Azure Cloud Services Office 365 Active Directory Exchange Server Windows Server Window Desktop IIS Web Servers SQL and C# Intergration FTP Firewalls File Migration Remote Management PowerShell forms Willing to take on almost any automation project big or small. Current working as a systems\​network administrator for a medium-sized software company and I'm looking for remote work that can be done outside working hours around my current job. If you need a PowerShell script editing or created I will be your man to do so! Email: [email protected] for more info. powershell active-directoryexchange-server

Updated on June 20, 2022

Comments

  • Richard
    Richard almost 2 years

    I have installed the MSMQ feature onto both server (win 2008 R2) and client machine (win 7) using the following Link. The Feature appears in the server manager and I am able to create a public or privet queue through the GUI. But when I come to try access the queue locally on the server through PowerShell (2.0) none of the Cmdlet's for MSMQ are recognized within the shell.

    Are there any further steps that I need to take to access MSMQ through PowerShell? Is there a MSMQ module that I need to load?

    Any advice on this would be appreciated.