2

I want to set permissions for one specific private message queue. I've found this related answer, but it is a much larger script that deletes queues first if they exist and then (re)creates them. That solution gets references to queues in one of two ways:

  1. Via [System.Messaging.MessageQueue]::Create(".\private$\somequeue"); or
  2. By looping through [System.Messaging.MessageQueue]::GetPrivateQueuesByMachine(".").

What I want to do is something like this:

GetPrivateQueueByName(".\private$\somequeue")  # Method doesn't exist!

But I have not found such a method. I've cycled through all Get* methods in the MessageQueue namespace.

Is there a way to get a single private queue by its name, or otherwise set permissions, without having to iterate all queues and/or recreate it?

Community
  • 1
  • 1
Jeroen
  • 60,696
  • 40
  • 206
  • 339

1 Answers1

1

This will allow you to add permissions to your queue:

[System.Reflection.Assembly]::LoadWithPartialName("System.Messaging") | Out-Null
(New-Object -TypeName "System.Messaging.MessageQueue" -ArgumentList $queue).SetPermissions(agrs here)

Where $queue is the queue address, e.g. ".\private$\MyQueue".

This uses SetPermissions method of MessageQueue.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
tom redfern
  • 30,562
  • 14
  • 91
  • 126