├── AddExchange.ps1 ├── AddMessage.ps1 ├── AddPermission.ps1 ├── AddQueue.ps1 ├── AddQueueBinding.ps1 ├── AddUser.ps1 ├── AddVirtualHost.ps1 ├── ApplyFilter.ps1 ├── ClearQueue.ps1 ├── Constants.ps1 ├── CopyMessage.ps1 ├── GetChannel.ps1 ├── GetConnection.ps1 ├── GetExchange.ps1 ├── GetItemsFromRabbitMQApi.ps1 ├── GetMessage.ps1 ├── GetNode.ps1 ├── GetOverview.ps1 ├── GetPermission.ps1 ├── GetQueue.ps1 ├── GetQueueBinding.ps1 ├── GetRabbitMQCredentials.ps1 ├── GetUser.ps1 ├── GetVirtualHost.ps1 ├── Invoke_RestMethodProxy.ps1 ├── LICENSE ├── MoveMessage.ps1 ├── NamesToString.ps1 ├── NormaliseCredentials.ps1 ├── PreventUnEscapeDotsAndSlashesOnUri.ps1 ├── README.md ├── RabbitMQTools.psd1 ├── RabbitMQTools.psm1 ├── RabbitMqTools.Format.Ps1xml ├── RegisterServer.ps1 ├── RemoveConnection.ps1 ├── RemoveExchange.ps1 ├── RemovePermission.ps1 ├── RemoveQueue.ps1 ├── RemoveQueueBinding.ps1 ├── RemoveUser.ps1 ├── RemoveVirtualHost.ps1 ├── SendItemsToOutput.ps1 ├── SetPermission.ps1 ├── SetUser.ps1 ├── TabExpansions.ps1 ├── Tests ├── AddExchange.Tests.ps1 ├── AddQueue.Tests.ps1 ├── AddVirtualHost.Tests.ps1 ├── GetExchange.Tests.ps1 ├── GetOverview.Tests.ps1 ├── GetVirtualHost.Tests.ps1 ├── RemoveExchange.Tests.ps1 ├── RemoveVirtualHost.Tests.ps1 └── TestSetup.ps1 ├── UnregisterServer.ps1 └── en-US ├── about_RabbitMQTools.help.txt └── about_UnEsapingDotsAndSlashes.help.txt /AddExchange.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds Exchange to RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQExchange allows for creating new Exchanges in given RabbitMQ server. 7 | 8 | To add Exchange to remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with names and parameters, including ComputerName, to create multiple Exchanges. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Add-RabbitMQExchange -Type direct TestExchange 18 | 19 | Creates direct exchange named TestExchange in the local RabbitMQ server. 20 | 21 | .EXAMPLE 22 | Add-RabbitMQExchange -Type direct TestExchange -Durable -AutoDelete -Internal -AlternateExchange e2 23 | 24 | Creates direct exchange named TestExchange in the local RabbitMQ server and sets its properties to be Durable, AutoDelete, Internal and to use alternate exchange called e2. 25 | 26 | .EXAMPLE 27 | Add-RabbitMQExchange -Type fanout TestExchange, ProdExchange 28 | 29 | Creates in the local RabbitMQ server two fanout exchanges named TestExchange and ProdExchange. 30 | 31 | .EXAMPLE 32 | Add-RabbitMQExchange -Type direct TestExchange -ComputerName myrabbitmq.servers.com 33 | 34 | Creates direct exchange named TestExchange in the myrabbitmq.servers.com server. 35 | 36 | .EXAMPLE 37 | @("e1", "e2") | Add-RabbitMQExchange -Type direct 38 | 39 | This command pipes list of exchanges to add to the RabbitMQ server. In the above example two new Exchanges named "e1" and "e2" will be created in local RabbitMQ server. 40 | 41 | .EXAMPLE 42 | $a = $( 43 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "e1", "Type"="direct"} 44 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "e2", "Type"="fanout"} 45 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "e3", "Type"="topic", Durable=$true, $Internal=$true} 46 | ) 47 | 48 | $a | Add-RabbitMQExchange 49 | 50 | Above example shows how to pipe parameters for creating new exchanges. 51 | 52 | In the above example three new exchanges will be created with different parameters. 53 | 54 | .INPUTS 55 | You can pipe Name, Type, Durable, AutoDelete, Internal, AlternateExchange, VirtualHost and ComputerName to this cmdlet. 56 | 57 | .LINK 58 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 59 | #> 60 | function Add-RabbitMQExchange 61 | { 62 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Medium")] 63 | Param 64 | ( 65 | # Name of RabbitMQ Exchange. 66 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 67 | [Alias("Exchange", "ExchangeName")] 68 | [string[]]$Name, 69 | 70 | # Type of the Exchange to create. 71 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 72 | [ValidateSet("topic", "fanout", "direct", "headers")] 73 | [string]$Type, 74 | 75 | # Determines whether the exchange should be Durable. 76 | [parameter(ValueFromPipelineByPropertyName=$true)] 77 | [switch]$Durable, 78 | 79 | # Determines whether the exchange will be deleted once all queues have finished using it. 80 | [parameter(ValueFromPipelineByPropertyName=$true)] 81 | [switch]$AutoDelete, 82 | 83 | # Determines whether the exchange should be Internal. 84 | [parameter(ValueFromPipelineByPropertyName=$true)] 85 | [switch]$Internal, 86 | 87 | # Allows to set alternate exchange to which all messages which cannot be routed will be send. 88 | [parameter(ValueFromPipelineByPropertyName=$true)] 89 | [Alias("alt")] 90 | [string]$AlternateExchange, 91 | 92 | # Name of RabbitMQ Virtual Host. 93 | [parameter(ValueFromPipelineByPropertyName=$true)] 94 | [Alias("vh", "vhost")] 95 | [string]$VirtualHost = $defaultVirtualhost, 96 | 97 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 98 | [parameter(ValueFromPipelineByPropertyName=$true)] 99 | [Alias("HostName", "hn", "cn")] 100 | [string]$ComputerName = $defaultComputerName, 101 | 102 | 103 | # UserName to use when logging to RabbitMq server. 104 | [Parameter(Mandatory=$true, ParameterSetName='login')] 105 | [string]$UserName, 106 | 107 | # Password to use when logging to RabbitMq server. 108 | [Parameter(Mandatory=$true, ParameterSetName='login')] 109 | [string]$Password, 110 | 111 | # Credentials to use when logging to RabbitMQ server. 112 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 113 | [PSCredential]$Credentials 114 | ) 115 | 116 | Begin 117 | { 118 | $Credentials = NormaliseCredentials 119 | } 120 | Process 121 | { 122 | if ($pscmdlet.ShouldProcess("server: $ComputerName, vhost: $VirtualHost", "Add exchange(s): $(NamesToString $Name '(all)')")) { 123 | 124 | $body = @{ 125 | type = "$Type" 126 | } 127 | 128 | if ($Durable) { $body.Add("durable", $true) } 129 | if ($AutoDelete) { $body.Add("auto_delete", $true) } 130 | if ($Internal) { $body.Add("internal", $true) } 131 | if ($AlternateExchange) { $body.Add("arguments", @{ "alternate-exchange"=$AlternateExchange }) } 132 | 133 | $bodyJson = $body | ConvertTo-Json 134 | 135 | foreach($n in $Name) 136 | { 137 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/exchanges/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($n))" 138 | Write-Verbose "Invoking REST API: $url" 139 | 140 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" -Body $bodyJson 141 | 142 | Write-Verbose "Created Exchange $n on server $ComputerName, Virtual Host $VirtualHost" 143 | $cnt++ 144 | } 145 | } 146 | } 147 | End 148 | { 149 | if ($cnt -gt 1) { Write-Verbose "Created $cnt Exchange(s)." } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /AddMessage.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets messages from RabbitMQ Queue. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQMessage cmdlet gets messages from RabbitMQ queue. 7 | 8 | The result may be zero, one or many RabbitMQ.Message objects. 9 | 10 | To get Connections from remote server you need to provide -ComputerName parameter. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | .EXAMPLE 15 | Add-RabbitMQMessage vh1 q1 16 | 17 | This command gets first message from queue "q1" on virtual host "vh1". 18 | 19 | .EXAMPLE 20 | Add-RabbitMQMessage test q1 -Count 10 21 | 22 | This command gets first 10 messages from queue "q1" on virtual host "vh1". 23 | 24 | .EXAMPLE 25 | Add-RabbitMQMessage test q1 127.0.0.1 26 | 27 | This command gets first message from queue "q1" on virtual host "vh1", server 127.0.0.1. 28 | 29 | .INPUTS 30 | 31 | .OUTPUTS 32 | By default, the cmdlet returns list of RabbitMQ.QueueMessage objects which describe connections. 33 | 34 | .LINK 35 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 36 | #> 37 | function Add-RabbitMQMessage 38 | { 39 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 40 | Param 41 | ( 42 | # Name of the virtual host to filter channels by. 43 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 44 | [Alias("vh", "vhost")] 45 | [string]$VirtualHost, 46 | 47 | # Name of RabbitMQ Exchange. 48 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 49 | [Alias("exchange")] 50 | [string]$ExchangeName, 51 | 52 | # Routing key to be used when publishing message. 53 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 54 | [Alias("rk")] 55 | [string]$RoutingKey, 56 | 57 | # Massage's payload 58 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=3)] 59 | [string]$Payload, 60 | 61 | # Array with message properties. 62 | [parameter(ValueFromPipelineByPropertyName=$true, Position=4)] 63 | $Properties, 64 | 65 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 66 | [parameter(ValueFromPipelineByPropertyName=$true)] 67 | [Alias("HostName", "hn", "cn")] 68 | [string]$ComputerName = $defaultComputerName, 69 | 70 | 71 | # UserName to use when logging to RabbitMq server. 72 | [Parameter(Mandatory=$true, ParameterSetName='login')] 73 | [string]$UserName, 74 | 75 | # Password to use when logging to RabbitMq server. 76 | [Parameter(Mandatory=$true, ParameterSetName='login')] 77 | [string]$Password, 78 | 79 | # Credentials to use when logging to RabbitMQ server. 80 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 81 | [PSCredential]$Credentials 82 | ) 83 | 84 | Begin 85 | { 86 | $Credentials = NormaliseCredentials 87 | 88 | if ($Properties -eq $null) { $Properties = @{} } 89 | } 90 | Process 91 | { 92 | if ($pscmdlet.ShouldProcess("server: $ComputerName/$VirtualHost", "Publish message to exchange $ExchangeName with routing key $RoutingKey")) 93 | { 94 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/exchanges/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($ExchangeName))/publish" 95 | Write-Verbose "Invoking REST API: $url" 96 | 97 | $body = @{ 98 | routing_key = $RoutingKey 99 | payload_encoding = "string" 100 | payload = $Payload 101 | properties = $Properties 102 | } 103 | 104 | $bodyJson = $body | ConvertTo-Json 105 | 106 | 107 | $retryCounter = 0 108 | 109 | while ($retryCounter -lt 3) 110 | { 111 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Post -ContentType "application/json" -Body $bodyJson 112 | 113 | if ($result.routed -ne $true) 114 | { 115 | Write-Warning "Message was no routed. Operation will be retried. URI: $url" 116 | $retryCounter++ 117 | } 118 | else 119 | { 120 | break 121 | } 122 | } 123 | } 124 | } 125 | End 126 | { 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /AddPermission.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds permissions to virtual host for a user. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQPermission cmdlet allows to add user permissions to virtual host. 7 | 8 | To add permissions to remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Add-RabbitMQPermission -VirtualHost '/' -User Admin -Configure .* -Read .* -Write .* 16 | 17 | Add configure, read and write permissions for user Admin to default virtual host (/). 18 | 19 | .EXAMPLE 20 | Add-RabbitMQPermission -ComputerName rabbitmq.server.com '/' Admin .* .* .* 21 | 22 | Add configure, read and write permissions for user Admin to default virtual host (/) on server rabbitmq.server.com. This command uses positional parameters. 23 | 24 | .INPUTS 25 | You can pipe VirtualHost, User, Configure, Read, Write and ComputerName to this cmdlet. 26 | 27 | .LINK 28 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 29 | #> 30 | function Add-RabbitMQPermission 31 | { 32 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Medium")] 33 | Param 34 | ( 35 | # Virtual host to set permission for. 36 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 37 | [Alias("vhost", "vh")] 38 | [string]$VirtualHost, 39 | 40 | # Name of user to set permission for. 41 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 42 | [string]$User, 43 | 44 | # Configure permission regexp. 45 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 46 | [string]$Configure, 47 | 48 | # Read permission regexp. 49 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=3)] 50 | [string]$Read, 51 | 52 | # Write permission regexp. 53 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=4)] 54 | [string]$Write, 55 | 56 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 57 | [parameter(ValueFromPipelineByPropertyName=$true)] 58 | [Alias("HostName", "hn", "cn")] 59 | [string]$ComputerName = $defaultComputerName, 60 | 61 | 62 | # UserName to use when logging to RabbitMq server. 63 | [Parameter(Mandatory=$true, ParameterSetName='login')] 64 | [string]$UserName, 65 | 66 | # Password to use when logging to RabbitMq server. 67 | [Parameter(Mandatory=$true, ParameterSetName='login')] 68 | [string]$Password, 69 | 70 | # Credentials to use when logging to RabbitMQ server. 71 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 72 | [PSCredential]$Credentials 73 | ) 74 | 75 | Begin 76 | { 77 | $Credentials = NormaliseCredentials 78 | 79 | $p = Get-RabbitMQPermission -ComputerName $ComputerName -Credentials $Credentials -VirtualHost $VirtualHost -User $User 80 | if ($p) { throw "Permissions to virtual host $VirtualHost for user $User already exist. To change permissions use Set-RabbitMQPermission cmdlet." } 81 | 82 | $cnt = 0 83 | } 84 | Process 85 | { 86 | if ($pscmdlet.ShouldProcess("server: $ComputerName", "Create permission to virtual host $VirtualHost for user $User : $Configure, $Read $Write")) 87 | { 88 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/permissions/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($User))" 89 | $body = @{ 90 | 'configure' = $Configure 91 | 'read' = $Read 92 | 'write' = $Write 93 | } | ConvertTo-Json 94 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" -Body $body 95 | 96 | Write-Verbose "Created permission to $VirtualHost for $User : $Configure, $Read, $Write" 97 | $cnt++ 98 | } 99 | } 100 | End 101 | { 102 | if ($cnt -gt 1) { Write-Verbose "Created $cnt permissions." } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /AddQueue.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds Queue to RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQQueue allows for creating new queues in RabbitMQ server. 7 | 8 | To add Queue to remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with Name, Queue parameters, VirtualHost and ComputerName to create multiple queues. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Add-RabbitMQQueue queue1 18 | 19 | This command adds new Queue named "queue1" to local RabbitMQ server. 20 | 21 | .EXAMPLE 22 | Add-RabbitMQQueue queue1, queue2 23 | 24 | This command adds two new queues named "queue1" and "queue2" to local RabbitMQ server. 25 | 26 | .EXAMPLE 27 | Add-RabbitMQQueue queue1 -ComputerName myrabbitmq.servers.com 28 | 29 | This command adds new queue named "queue1" to myrabbitmq.servers.com server. 30 | 31 | .EXAMPLE 32 | @("queue1", "queue2") | Add-RabbitMQQueue 33 | 34 | This command pipes list of Queues to add to the RabbitMQ server. In the above example two new queues named "queue1" and "queue2" will be created in local RabbitMQ server. 35 | 36 | .EXAMPLE 37 | $a = $( 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "vh1"} 39 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "vh2"} 40 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "vh3"} 41 | ) 42 | 43 | 44 | $a | Add-RabbitMQQueue 45 | 46 | Above example shows how to pipe queue definitions to Add-RabbitMQQueue cmdlet. 47 | 48 | .INPUTS 49 | You can pipe VirtualHost names and optionally ComputerNames to this cmdlet. 50 | 51 | .LINK 52 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 53 | #> 54 | function Add-RabbitMQQueue 55 | { 56 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Low")] 57 | Param 58 | ( 59 | # Name of RabbitMQ Queue. 60 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 61 | [Alias("queue", "QueueName")] 62 | [string[]]$Name, 63 | 64 | # Name of the virtual host to filter channels by. 65 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 66 | [Alias("vh", "vhost")] 67 | [string]$VirtualHost, 68 | 69 | # Determines whether the queue should be durable. 70 | [parameter(ValueFromPipelineByPropertyName=$true)] 71 | [switch]$Durable = $false, 72 | 73 | # Determines whether the queue should be deleted automatically after all consumers have finished using it. 74 | [parameter(ValueFromPipelineByPropertyName=$true)] 75 | [switch]$AutoDelete = $false, 76 | 77 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 78 | [parameter(ValueFromPipelineByPropertyName=$true)] 79 | [Alias("HostName", "hn", "cn")] 80 | [string]$ComputerName = $defaultComputerName, 81 | 82 | 83 | # UserName to use when logging to RabbitMq server. 84 | [Parameter(Mandatory=$true, ParameterSetName='login')] 85 | [string]$UserName, 86 | 87 | # Password to use when logging to RabbitMq server. 88 | [Parameter(Mandatory=$true, ParameterSetName='login')] 89 | [string]$Password, 90 | 91 | # Credentials to use when logging to RabbitMQ server. 92 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 93 | [PSCredential]$Credentials 94 | ) 95 | 96 | Begin 97 | { 98 | $Credentials = NormaliseCredentials 99 | $cnt = 0 100 | } 101 | Process 102 | { 103 | if ($pscmdlet.ShouldProcess("server: $ComputerName/$VirtualHost", "Add queue(s): $(NamesToString $Name '(all)'); Durable=$Durable, AutoDelete=$AutoDelete")) 104 | { 105 | foreach($n in $Name) 106 | { 107 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/queues/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($n))" 108 | Write-Verbose "Invoking REST API: $url" 109 | 110 | $body = @{} 111 | if ($Durable) { $body.Add("durable", $true) } 112 | if ($AutoDelete) { $body.Add("auto_delete", $true) } 113 | 114 | $bodyJson = $body | ConvertTo-Json 115 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" -Body $bodyJson 116 | 117 | Write-Verbose "Created Queue $n on $ComputerName/$VirtualHost" 118 | $cnt++ 119 | } 120 | } 121 | } 122 | End 123 | { 124 | Write-Verbose "Created $cnt Queue(s)." 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /AddQueueBinding.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds binding between RabbitMQ exchange and queue. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQQueueBinding binds RabbitMQ exchange with queue using RoutingKey 7 | 8 | To add QueueBinding to remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Add-RabbitMQQueueBinding vh1 e1 q1 'e1-q1' 16 | 17 | This command binds exchange "e1" with queue "q1" using routing key "e1-q1". The operation is performed on local server in virtual host vh1. 18 | 19 | .EXAMPLE 20 | Add-RabbitMQQueueBinding '/' e1 q1 'e1-q1' 127.0.01 21 | 22 | This command binds exchange "e1" with queue "q1" using routing key "e1-q1". The operation is performed on server 127.0.0.1 in default virtual host (/). 23 | 24 | .INPUTS 25 | 26 | .LINK 27 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 28 | #> 29 | function Add-RabbitMQQueueBinding 30 | { 31 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Low")] 32 | Param 33 | ( 34 | # Name of the virtual host. 35 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 36 | [Alias("vh", "vhost")] 37 | [string]$VirtualHost = $defaultVirtualhost, 38 | 39 | # Name of RabbitMQ Exchange. 40 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 41 | [Alias("exchange")] 42 | [string]$ExchangeName, 43 | 44 | # Name of RabbitMQ Queue. 45 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 46 | [Alias("queue", "QueueName")] 47 | [string]$Name, 48 | 49 | # Routing key. 50 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=3)] 51 | [Alias("rk")] 52 | [string]$RoutingKey, 53 | 54 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 55 | [parameter(ValueFromPipelineByPropertyName=$true, Position=4)] 56 | [Alias("HostName", "hn", "cn")] 57 | [string]$ComputerName = $defaultComputerName, 58 | 59 | 60 | # UserName to use when logging to RabbitMq server. 61 | [Parameter(Mandatory=$true, ParameterSetName='login')] 62 | [string]$UserName, 63 | 64 | # Password to use when logging to RabbitMq server. 65 | [Parameter(Mandatory=$true, ParameterSetName='login')] 66 | [string]$Password, 67 | 68 | # Credentials to use when logging to RabbitMQ server. 69 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 70 | [PSCredential]$Credentials 71 | ) 72 | 73 | Begin 74 | { 75 | $Credentials = NormaliseCredentials 76 | $cnt = 0 77 | } 78 | Process 79 | { 80 | if ($pscmdlet.ShouldProcess("$ComputerName/$VirtualHost", "Add queue binding from exchange $ExchangeName to queue $Name with routing key $RoutingKey")) 81 | { 82 | foreach($n in $Name) 83 | { 84 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/bindings/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/e/$([System.Web.HttpUtility]::UrlEncode($ExchangeName))/q/$([System.Web.HttpUtility]::UrlEncode($Name))" 85 | Write-Verbose "Invoking REST API: $url" 86 | 87 | $body = @{ 88 | "routing_key" = $RoutingKey 89 | } 90 | 91 | $bodyJson = $body | ConvertTo-Json 92 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Post -ContentType "application/json" -Body $bodyJson 93 | 94 | Write-Verbose "Bound exchange $ExchangeName to queue $Name $n on $ComputerName/$VirtualHost" 95 | $cnt++ 96 | } 97 | } 98 | } 99 | End 100 | { 101 | Write-Verbose "Created $cnt Binding(s)." 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /AddUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds user to RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQUser cmdlet allows to create new users in RabbitMQ server. 7 | 8 | To add a user to remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Add-RabbitMQUser -Name Admin -NewPassword p4ssw0rd -Tag administrator 16 | 17 | Create new user with name Admin having administrator tags set. User is added to local RabbitMQ server. 18 | 19 | .EXAMPLE 20 | Add-RabbitMQUser -ComputerName rabbitmq.server.com Admin p4ssw0rd administrator 21 | 22 | Create new user with name "Admin", password "p4ssw0rd" having "administrator" tags set. User is added to rabbitmq.server.com server. This command uses positional parameters. 23 | Note that password for new user is specified as -NewPassword parameter and not -Password parameter, which is used for authorisation to the server. 24 | 25 | .INPUTS 26 | You can pipe Name, NewPassword, Tags and ComputerName to this cmdlet. 27 | 28 | .LINK 29 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 30 | #> 31 | function Add-RabbitMQUser 32 | { 33 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Low")] 34 | Param 35 | ( 36 | # Name of user to create. 37 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 38 | [string]$Name, 39 | 40 | # Password for new user. 41 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 42 | [string]$NewPassword, 43 | 44 | # Comma-separated list of user tags. 45 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 46 | [ValidateSet("administrator", "monitoring", "policymaker", "management")] 47 | [string[]]$Tag, 48 | 49 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 50 | [parameter(ValueFromPipelineByPropertyName=$true)] 51 | [Alias("HostName", "hn", "cn")] 52 | [string]$ComputerName = $defaultComputerName, 53 | 54 | 55 | # UserName to use when logging to RabbitMq server. 56 | [Parameter(Mandatory=$true, ParameterSetName='login')] 57 | [string]$UserName, 58 | 59 | # Password to use when logging to RabbitMq server. 60 | [Parameter(Mandatory=$true, ParameterSetName='login')] 61 | [string]$Password, 62 | 63 | # Credentials to use when logging to RabbitMQ server. 64 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 65 | [PSCredential]$Credentials 66 | ) 67 | 68 | Begin 69 | { 70 | $Credentials = NormaliseCredentials 71 | $cnt = 0 72 | } 73 | Process 74 | { 75 | if ($pscmdlet.ShouldProcess("server: $ComputerName", "Add user $Name with tag: $Tag")) 76 | { 77 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/users/$([System.Web.HttpUtility]::UrlEncode($Name))" 78 | $body = @{ 79 | 'password' = $NewPassword 80 | 'tags' = $Tag -join ',' 81 | } | ConvertTo-Json 82 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" -Body $body 83 | 84 | Write-Verbose "Created user $User with tags $Tag" 85 | $cnt++ 86 | } 87 | } 88 | End 89 | { 90 | if ($cnt -gt 1) { Write-Verbose "Created $cnt new users." } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /AddVirtualHost.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds Virtual Hosts to RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Add-RabbitMQVirtualHost allows for creating new Virtual Hosts in given RabbitMQ server. 7 | 8 | To add Virtual Hosts to remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with names and, optionally, with computer names to create multiple VirtualHosts. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Add-RabbitMQVirtualHost testHost 18 | 19 | This command adds new Virtual Host named "testHost" to local RabbitMQ server. 20 | 21 | .EXAMPLE 22 | Add-RabbitMQVirtualHost VHost1, VHost2 23 | 24 | This command adds two new Virtual Hosts named "VHost1" and "VHost2" to local RabbitMQ server. 25 | 26 | .EXAMPLE 27 | Add-RabbitMQVirtualHost testHost -ComputerName myrabbitmq.servers.com 28 | 29 | This command adds new Virtual Host named "testHost" to myrabbitmq.servers.com server. 30 | 31 | .EXAMPLE 32 | @("VHost1", "VHost2") | Add-RabbitMQVirtualHost 33 | 34 | This command pipes list of Virtual Hosts to add to the RabbitMQ server. In the above example two new Virtual Hosts named "VHost1" and "VHost2" will be created in local RabbitMQ server. 35 | 36 | .EXAMPLE 37 | $a = $( 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "vh1"} 39 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "vh2"} 40 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "vh3"} 41 | ) 42 | 43 | 44 | $a | Add-RabbitMQVirtualHost 45 | 46 | Above example shows how to pipe both Virtual Host name and Computer Name to specify server on which the Virtual Host should be created. 47 | 48 | In the above example two new Virtual Hosts named "vh1" and "vh1" will be created in RabbitMQ local server, and one Virtual Host named "vh3" will be created on the server 127.0.0.1. 49 | 50 | .INPUTS 51 | You can pipe VirtualHost names and optionally ComputerNames to this cmdlet. 52 | 53 | .LINK 54 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 55 | #> 56 | function Add-RabbitMQVirtualHost 57 | { 58 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Low")] 59 | Param 60 | ( 61 | # Name of RabbitMQ Virtual Host. 62 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 63 | [Alias("vh", "VirtualHost")] 64 | [string[]]$Name = "", 65 | 66 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 67 | [parameter(ValueFromPipelineByPropertyName=$true)] 68 | [Alias("HostName", "hn", "cn")] 69 | [string]$ComputerName = $defaultComputerName, 70 | 71 | 72 | # UserName to use when logging to RabbitMq server. 73 | [Parameter(Mandatory=$true, ParameterSetName='login')] 74 | [string]$UserName, 75 | 76 | # Password to use when logging to RabbitMq server. 77 | [Parameter(Mandatory=$true, ParameterSetName='login')] 78 | [string]$Password, 79 | 80 | # Credentials to use when logging to RabbitMQ server. 81 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 82 | [PSCredential]$Credentials 83 | ) 84 | 85 | Begin 86 | { 87 | $Credentials = NormaliseCredentials 88 | $cnt = 0 89 | } 90 | Process 91 | { 92 | if (-not $pscmdlet.ShouldProcess("server: $ComputerName", "Add vhost(s): $(NamesToString $Name '(all)')")) { 93 | foreach ($qn in $Name) 94 | { 95 | Write "Creating new Virtual Host $qn on server $ComputerName" 96 | $cnt++ 97 | } 98 | 99 | return 100 | } 101 | 102 | foreach($n in $Name) 103 | { 104 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/vhosts/$([System.Web.HttpUtility]::UrlEncode($n))" 105 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" 106 | 107 | Write-Verbose "Created Virtual Host $n on server $ComputerName" 108 | $cnt++ 109 | } 110 | } 111 | End 112 | { 113 | Write-Verbose "Created $cnt Virtual Host(s)." 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /ApplyFilter.ps1: -------------------------------------------------------------------------------- 1 | function ApplyFilter 2 | { 3 | Param ( 4 | [parameter()] 5 | [PSObject[]]$items, 6 | 7 | [parameter(Mandatory=$true)] 8 | [string]$prop, 9 | 10 | [string[]]$name 11 | ) 12 | 13 | if (-not $name) { return $items } 14 | 15 | # apply property filter 16 | $filter = @() 17 | foreach($n in $name) { $filter += '$_.' + $prop + '-like "' + $n + '"' } 18 | 19 | $sb = [scriptblock]::create($filter -join ' -or ') 20 | return $items | ? $sb 21 | } 22 | -------------------------------------------------------------------------------- /ClearQueue.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Purges all messages from RabbitMQ Queue. 4 | 5 | .DESCRIPTION 6 | The Clear-RabbitMQQueue removes all messages from given RabbitMQ queue. 7 | 8 | To remove message from Queue on remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Clear-RabbitMQQueue vh1 q1 16 | 17 | Removes all messages from queue "q1" in Virtual Host "vh1" on local computer. 18 | 19 | .EXAMPLE 20 | Clear-RabbitMQQueue -VirtualHost vh1 -Name q1 21 | 22 | Removes all messages from queue "q1" in Virtual Host "vh1" on local computer. 23 | 24 | .EXAMPLE 25 | Clear-RabbitMQQueue -VirtualHost vh1 -Name q1 -ComputerName rabbitmq.server.com 26 | 27 | Removes all messages from queue "q1" in Virtual Host "vh1" on "rabbitmq.server.com" server. 28 | #> 29 | function Clear-RabbitMQQueue 30 | { 31 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 32 | Param 33 | ( 34 | # Name of RabbitMQ Virtual Host. 35 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 36 | [Alias("vh", "vhost")] 37 | [string]$VirtualHost = $defaultVirtualHost, 38 | 39 | # The name of the queue from which to receive messages 40 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 41 | [Alias("qn", "QueueName")] 42 | [string]$Name, 43 | 44 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 45 | [parameter(ValueFromPipelineByPropertyName=$true, Position=2)] 46 | [Alias("cn", "HostName")] 47 | [string]$ComputerName = $defaultComputerName, 48 | 49 | 50 | # UserName to use when logging to RabbitMq server. 51 | [Parameter(Mandatory=$true, ParameterSetName='login')] 52 | [string]$UserName, 53 | 54 | # Password to use when logging to RabbitMq server. 55 | [Parameter(Mandatory=$true, ParameterSetName='login')] 56 | [string]$Password, 57 | 58 | # Credentials to use when logging to RabbitMQ server. 59 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 60 | [PSCredential]$Credentials 61 | ) 62 | 63 | Begin 64 | { 65 | $Credentials = NormaliseCredentials 66 | } 67 | Process 68 | { 69 | if ($pscmdlet.ShouldProcess("server: $ComputerName/$VirtualHost", "purge queue $Name")) 70 | { 71 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/queues/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($Name))/contents" 72 | Write-Verbose "Invoking REST API: $url" 73 | 74 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete 75 | } 76 | } 77 | End 78 | { 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Constants.ps1: -------------------------------------------------------------------------------- 1 | $defaultComputerName = "localhost" 2 | $defaultVirtualhost = "/" 3 | $defaultUserName = "guest" 4 | $defaultPassword = "guest" 5 | -------------------------------------------------------------------------------- /CopyMessage.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Copies messages from one RabbitMQ Queue to another. 4 | 5 | .DESCRIPTION 6 | The Copy-RabbitMQMessage cmdlet allows to copy messages from one RabbitMQ queue to another. 7 | Both source and destination queues must be in the same Virtual Host. 8 | The "exchange" and "routing_key" properties on copied messages will ba changed. 9 | 10 | Copying messages is done by creating new exchange, binding both from and to queues to it and republishing messages from source queue. 11 | 12 | The cmdlet is not designed to be used on sensitive data. 13 | 14 | WARNING 15 | This operation is not transactional and may result in not all messages being copied or some messages being duplicated. 16 | Also, if there are new messages published to the source queue or messages are consumed, then the operation may fail with unexpected result. 17 | Because of the nature of copying messages, this operation may change order of messages in the source queue. 18 | 19 | 20 | To copy messages on remote server you need to provide -ComputerName parameter. 21 | 22 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 23 | 24 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 25 | 26 | .EXAMPLE 27 | Copy-RabbitMQMessage vh1 q1 q2 28 | 29 | Copy all messages from q1 to q2 on Virtual Host vh1. 30 | 31 | .EXAMPLE 32 | Copy-RabbitMQMessage vh1 q1 q2 5 33 | 34 | Copy first 5 messages from q1 to q2 on Virtual Host vh1. 35 | 36 | .EXAMPLE 37 | Copy-RabbitMQMessage -VirtualHost vh1 -$SourceQueueName q1 -$DestinationQueueName q2 -Count 5 38 | 39 | Copy first 5 messages from q1 to q2 on Virtual Host vh1. 40 | 41 | .INPUTS 42 | 43 | .OUTPUTS 44 | By default, the cmdlet returns list of RabbitMQ.QueueMessage objects which describe connections. 45 | 46 | .LINK 47 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 48 | #> 49 | function Copy-RabbitMQMessage 50 | { 51 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='High')] 52 | Param 53 | ( 54 | # Name of the virtual host to filter channels by. 55 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 56 | [Alias("vh", "vhost")] 57 | [string]$VirtualHost, 58 | 59 | # Name of RabbitMQ Queue from which messages should be copied. 60 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 61 | [Alias("from", "fromQueue")] 62 | [string]$SourceQueueName, 63 | 64 | # Name of RabbitMQ Queue to which messages should be copied. 65 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 66 | [Alias("to", "toQueue")] 67 | [string]$DestinationQueueName, 68 | 69 | # If specified, gives the number of messages to copy. 70 | [parameter(ValueFromPipelineByPropertyName=$true, Position=3)] 71 | [int]$Count, 72 | 73 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 74 | [parameter(ValueFromPipelineByPropertyName=$true, Position=4)] 75 | [Alias("HostName", "hn", "cn")] 76 | [string]$ComputerName = $defaultComputerName, 77 | 78 | 79 | # UserName to use when logging to RabbitMq server. 80 | [Parameter(Mandatory=$true, ParameterSetName='login')] 81 | [string]$UserName, 82 | 83 | # Password to use when logging to RabbitMq server. 84 | [Parameter(Mandatory=$true, ParameterSetName='login')] 85 | [string]$Password, 86 | 87 | # Credentials to use when logging to RabbitMQ server. 88 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 89 | [PSCredential]$Credentials 90 | ) 91 | 92 | Begin 93 | { 94 | $Credentials = NormaliseCredentials 95 | $cnt = 0 96 | $requiresMessageRemoval = $SourceQueueName -ne $DestinationQueueName 97 | } 98 | Process 99 | { 100 | $s = @{$true=$Count;$false='all'}[$Count -gt 0] 101 | if ($pscmdlet.ShouldProcess("server: $ComputerName/$VirtualHost", "Copy $s messages from queue $SourceQueueName to queue $DestinationQueueName.")) 102 | { 103 | $ename = "RabbitMQTools_copy" 104 | $routingKey = "RabbitMQTools_copy" 105 | Add-RabbitMQExchange -ComputerName $ComputerName -VirtualHost $VirtualHost -Type fanout -AutoDelete -Name $ename -Credentials $Credentials 106 | Add-RabbitMQQueueBinding -ComputerName $ComputerName -VirtualHost $VirtualHost -ExchangeName $ename -Name $SourceQueueName -RoutingKey $routingKey -Credentials $Credentials 107 | Add-RabbitMQQueueBinding -ComputerName $ComputerName -VirtualHost $VirtualHost -ExchangeName $ename -Name $DestinationQueueName -RoutingKey $routingKey -Credentials $Credentials 108 | 109 | try 110 | { 111 | $m = Get-RabbitMQMessage -Credentials $Credentials -ComputerName $ComputerName -VirtualHost $VirtualHost -Name $SourceQueueName 112 | $c = $m.message_count + 1 113 | 114 | if ($Count -eq 0 -or $Count -gt $c ) { $Count = $c } 115 | Write-Verbose "There are $Count messages to be copied." 116 | 117 | for ($i = 1; $i -le $Count; $i++) 118 | { 119 | # get message to be copies, but do not remove it from the server yet. 120 | $m = Get-RabbitMQMessage -Credentials $Credentials -ComputerName $ComputerName -VirtualHost $VirtualHost -Name $SourceQueueName 121 | 122 | # publish message to copying exchange, this will publish it onto dest queue as well as src queue. 123 | Add-RabbitMQMessage -Credentials $Credentials -ComputerName $ComputerName -VirtualHost $VirtualHost -ExchangeName $ename -RoutingKey $routingKey -Payload $m.payload -Properties $m.properties 124 | 125 | # remove message from src queue. It has been published step earlier. 126 | if ($requiresMessageRemoval) { $m = Get-RabbitMQMessage -Credentials $Credentials -ComputerName $ComputerName -VirtualHost $VirtualHost -Name $SourceQueueName -Remove } 127 | 128 | [int]$p = ($i * 100) / $Count 129 | if ($p -gt 100) { $p = 100 } 130 | Write-Progress -Activity "Copying messages from $SourceQueueName to $DestinationQueueName" -Status "Copying message $i out of $Count" -PercentComplete $p 131 | 132 | Write-Verbose "published message $i out of $Count" 133 | $cnt++ 134 | } 135 | } 136 | finally 137 | { 138 | Remove-RabbitMQExchange -Credentials $Credentials -ComputerName $ComputerName -VirtualHost $VirtualHost -Name $ename -Confirm:$false 139 | } 140 | } 141 | } 142 | End 143 | { 144 | Write-Verbose "`r`nCopied $cnt messages from queue $SourceQueueName to queue $DestinationQueueName." 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /GetChannel.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets open RabbitMQ Channels. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQChannel cmdlet gets list of opened channels. 7 | 8 | The cmdlet allows you to show list of opened channels or filter them by name using wildcards. 9 | The result may be zero, one or many RabbitMQ.Channel objects. 10 | 11 | To get Nodes from remote server you need to provide -ComputerName parameter. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQChannel 17 | 18 | This command gets a list of opened channels. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQChannel -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of opened channels to myrabbitmq.servers.com server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQChannel *53232* 27 | 28 | This command gets a list of all opened channels which name has "53232" number in it. 29 | 30 | .EXAMPLE 31 | Get-RabbitMQChannel -VirtualHost vhost1 32 | 33 | This command gets all opened channels which are using Virtual Host named "vhost1". 34 | 35 | 36 | .EXAMPLE 37 | @("*53232*", "*53234*") | Get-RabbitMQChannel 38 | 39 | This command pipes channel name filters to Get-RabbitMQChannel cmdlet. 40 | 41 | .INPUTS 42 | You can pipe channel Name to filter the results. 43 | 44 | .OUTPUTS 45 | By default, the cmdlet returns list of RabbitMQ.Channel objects which describe cluster nodes. 46 | 47 | .LINK 48 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 49 | #> 50 | function Get-RabbitMQChannel 51 | { 52 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 53 | Param 54 | ( 55 | # Name of RabbitMQ Node. 56 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 57 | [Alias("Channel", "ChannelName")] 58 | [string[]]$Name = "", 59 | 60 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 61 | [parameter(ValueFromPipelineByPropertyName=$true)] 62 | [Alias("HostName", "hn", "cn")] 63 | [string]$ComputerName = $defaultComputerName, 64 | 65 | # Name of the virtual host to filter channels by. 66 | [parameter(ValueFromPipelineByPropertyName=$true)] 67 | [Alias("vh", "vhost")] 68 | [string]$VirtualHost, 69 | 70 | 71 | # UserName to use when logging to RabbitMq server. 72 | [Parameter(Mandatory=$true, ParameterSetName='login')] 73 | [string]$UserName, 74 | 75 | # Password to use when logging to RabbitMq server. 76 | [Parameter(Mandatory=$true, ParameterSetName='login')] 77 | [string]$Password, 78 | 79 | # Credentials to use when logging to RabbitMQ server. 80 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 81 | [PSCredential]$Credentials 82 | ) 83 | 84 | Begin 85 | { 86 | $Credentials = NormaliseCredentials 87 | } 88 | Process 89 | { 90 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get node(s): $(NamesToString $Name '(all)')")) 91 | { 92 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "channels" 93 | 94 | $result = ApplyFilter $result 'name' $Name 95 | if ($VirtualHost) { $result = ApplyFilter $result 'vhost' $VirtualHost } 96 | 97 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 98 | 99 | SendItemsToOutput $result "RabbitMQ.Channel" 100 | } 101 | } 102 | End 103 | { 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /GetConnection.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets Connections to the server. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQConnection cmdlet gets connections to the RabbitMQ server. 7 | 8 | The cmdlet allows you to show all Connections or filter them by name using wildcards. 9 | The result may be zero, one or many RabbitMQ.Connection objects. 10 | 11 | To get Connections from remote server you need to provide -ComputerName parameter. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQConnection 17 | 18 | This command gets a list of all connections to local RabbitMQ server. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQConnection -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of all connections myrabbitmq.servers.com server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQConnection con1* 27 | 28 | This command gets a list of all Connections with name starting with "con1". 29 | 30 | .EXAMPLE 31 | Get-RabbitMQConnection private*, public* 32 | 33 | This command gets a list of all Connections with name starting with either "private" or "public". 34 | 35 | 36 | .EXAMPLE 37 | @("private*", "*public") | Get-RabbitMQConnection 38 | 39 | This command pipes name filters to Get-RabbitMQConnection cmdlet. 40 | 41 | .INPUTS 42 | You can pipe Name to filter the results. 43 | 44 | .OUTPUTS 45 | By default, the cmdlet returns list of RabbitMQ.Connection objects which describe connections. 46 | 47 | .LINK 48 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 49 | #> 50 | function Get-RabbitMQConnection 51 | { 52 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 53 | Param 54 | ( 55 | # Name of RabbitMQ Connection. 56 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 57 | [Alias("Connection", "ConnectionName")] 58 | [string[]]$Name = "", 59 | 60 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 61 | [parameter(ValueFromPipelineByPropertyName=$true)] 62 | [Alias("HostName", "hn", "cn")] 63 | [string]$ComputerName = $defaultComputerName, 64 | 65 | 66 | # UserName to use when logging to RabbitMq server. 67 | [Parameter(Mandatory=$true, ParameterSetName='login')] 68 | [string]$UserName, 69 | 70 | # Password to use when logging to RabbitMq server. 71 | [Parameter(Mandatory=$true, ParameterSetName='login')] 72 | [string]$Password, 73 | 74 | # Credentials to use when logging to RabbitMQ server. 75 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 76 | [PSCredential]$Credentials 77 | ) 78 | 79 | Begin 80 | { 81 | $Credentials = NormaliseCredentials 82 | } 83 | Process 84 | { 85 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get connection(s): $(NamesToString $Name '(all)')")) 86 | { 87 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "connections" 88 | 89 | $result = ApplyFilter $result 'name' $Name 90 | 91 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 92 | 93 | SendItemsToOutput $result "RabbitMQ.Connection" 94 | } 95 | } 96 | End 97 | { 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /GetExchange.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets Virtual Hosts registered with the server. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQVirtualHost gets Virtual Hosts registered with RabbitMQ server. 7 | 8 | The cmdlet allows you to show all Virtual Hosts or filter them by name using wildcards. 9 | The result may be zero, one or many RabbitMQ.VirtualHost objects. 10 | 11 | To get Virtual Hosts from remote server you need to provide -ComputerName. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQVirtualHost 17 | 18 | This command gets a list of all Virtual Hosts registered with RabbitMQ on local server. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQVirtualHost -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of all Virtual Hosts registered with RabbitMQ on myrabbitmq.servers.com server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQVirtualHost private* 27 | 28 | This command gets a list of all Virtual Hosts which name starts with "private". 29 | 30 | .EXAMPLE 31 | Get-RabbitMQVirtualHost private*, public* 32 | 33 | This command gets a list of all Virtual Hosts which name starts with "private" or "public". 34 | 35 | .EXAMPLE 36 | Get-RabbitMQVirtualHost private*, public* 37 | 38 | This command gets a list of all Virtual Hosts which name starts with "private" or "public". 39 | 40 | .EXAMPLE 41 | Get-RabbitMQVirtualHost marketing_private | select * 42 | 43 | This command selects all properties for given Virtual Host. 44 | 45 | .EXAMPLE 46 | @("private*", "*public") | Get-RabbitMQVirtualHost 47 | 48 | This command pipes name filters to Get-RabbitMQVirtualHost cmdlet. 49 | 50 | .INPUTS 51 | You can pipe Virtual Host names to filter results. 52 | 53 | .OUTPUTS 54 | By default, the cmdlet returns list of RabbitMQ.VirtualHost objects which describe Virtual Hosts. 55 | 56 | .LINK 57 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 58 | #> 59 | function Get-RabbitMQExchange 60 | { 61 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 62 | Param 63 | ( 64 | # Name of RabbitMQ Exchange. 65 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 66 | [Alias("ex", "Exchange", "ExchangeName")] 67 | [string[]]$Name = "", 68 | 69 | # Name of RabbitMQ Virtual Host. 70 | [parameter(ValueFromPipelineByPropertyName=$true)] 71 | [Alias("vh")] 72 | [string]$VirtualHost = "", 73 | 74 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 75 | [parameter(ValueFromPipelineByPropertyName=$true)] 76 | [Alias("HostName", "hn", "cn")] 77 | [string]$ComputerName = $defaultComputerName, 78 | 79 | 80 | # UserName to use when logging to RabbitMq server. 81 | [Parameter(Mandatory=$true, ParameterSetName='login')] 82 | [string]$UserName, 83 | 84 | # Password to use when logging to RabbitMq server. 85 | [Parameter(Mandatory=$true, ParameterSetName='login')] 86 | [string]$Password, 87 | 88 | # Credentials to use when logging to RabbitMQ server. 89 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 90 | [PSCredential]$Credentials 91 | ) 92 | 93 | Begin 94 | { 95 | $Credentials = NormaliseCredentials 96 | } 97 | Process 98 | { 99 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get exchange(s): $(NamesToString $Name '(all)')")) 100 | { 101 | $exchanges = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "exchanges" 102 | 103 | $result = ApplyFilter $exchanges 'vhost' $VirtualHost 104 | $result = ApplyFilter $result 'name' $Name 105 | 106 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 107 | 108 | SendItemsToOutput $result "RabbitMQ.Exchange" 109 | } 110 | } 111 | End 112 | { 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /GetItemsFromRabbitMQApi.ps1: -------------------------------------------------------------------------------- 1 | function GetItemsFromRabbitMQApi 2 | { 3 | [CmdletBinding(DefaultParameterSetName='login')] 4 | Param 5 | ( 6 | [parameter(Mandatory=$true, ParameterSetName='login', Position = 0)] 7 | [string]$cn, 8 | 9 | [parameter(Mandatory=$true, ParameterSetName='login', Position = 1)] 10 | [string]$userName, 11 | 12 | [parameter(Mandatory=$true, ParameterSetName='login', Position = 2)] 13 | [string]$password, 14 | 15 | [parameter(Mandatory=$true, ParameterSetName='login', Position = 3)] 16 | [string]$fn, 17 | 18 | 19 | [parameter(Mandatory=$true, ParameterSetName='cred', Position = 0)] 20 | [string]$computerName, 21 | 22 | [parameter(Mandatory=$true, ParameterSetName='cred', Position = 1)] 23 | [PSCredential]$cred, 24 | 25 | [parameter(Mandatory=$true, ParameterSetName='cred', Position = 2)] 26 | [string]$function 27 | ) 28 | 29 | Add-Type -AssemblyName System.Web 30 | #Add-Type -AssemblyName System.Net 31 | 32 | if ($PsCmdlet.ParameterSetName -eq "login") 33 | { 34 | $computerName = $cn 35 | $cred = GetRabbitMqCredentials $userName $password 36 | $function = $fn 37 | } 38 | 39 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($computerName)):15672/api/$function" 40 | Write-Verbose "Invoking REST API: $url" 41 | 42 | return Invoke-RestMethod $url -Credential $cred -DisableKeepAlive -AllowEscapedDotsAndSlashes 43 | } 44 | -------------------------------------------------------------------------------- /GetMessage.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets messages from RabbitMQ Queue. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQMessage cmdlet gets messages from RabbitMQ queue. 7 | 8 | The result may be zero, one or many RabbitMQ.Message objects. 9 | 10 | To get Connections from remote server you need to provide -ComputerName parameter. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | .EXAMPLE 15 | Get-RabbitMQMessage vh1 q1 16 | 17 | This command gets first message from queue "q1" on virtual host "vh1". 18 | 19 | .EXAMPLE 20 | Get-RabbitMQMessage test q1 -Count 10 21 | 22 | This command gets first 10 messages from queue "q1" on virtual host "vh1". 23 | 24 | .EXAMPLE 25 | Get-RabbitMQMessage test q1 127.0.0.1 26 | 27 | This command gets first message from queue "q1" on virtual host "vh1", server 127.0.0.1. 28 | 29 | .INPUTS 30 | 31 | .OUTPUTS 32 | By default, the cmdlet returns list of RabbitMQ.QueueMessage objects which describe connections. 33 | 34 | .LINK 35 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 36 | #> 37 | function Get-RabbitMQMessage 38 | { 39 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 40 | Param 41 | ( 42 | # Name of RabbitMQ Queue. 43 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 44 | [Alias("queue", "QueueName")] 45 | [string]$Name = "", 46 | 47 | # Name of the virtual host to filter channels by. 48 | [parameter(ValueFromPipelineByPropertyName=$true)] 49 | [Alias("vh", "vhost")] 50 | [string]$VirtualHost, 51 | 52 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 53 | [parameter(ValueFromPipelineByPropertyName=$true)] 54 | [Alias("HostName", "hn", "cn")] 55 | [string]$ComputerName = $defaultComputerName, 56 | 57 | 58 | # Number of messages to get. Default value is 1. 59 | [parameter(ValueFromPipelineByPropertyName=$true)] 60 | [int]$Count = 1, 61 | 62 | # Indicates whether messages should be removed from the queue. Default setting is to not remove messages. 63 | [parameter(ValueFromPipelineByPropertyName=$true)] 64 | [switch]$Remove, 65 | 66 | # Determines message body encoding. 67 | [parameter(ValueFromPipelineByPropertyName=$true)] 68 | [ValidateSet("auto", "base64")] 69 | [string]$Encoding = "auto", 70 | 71 | # Indicates whether messages body should be truncated to given size (in bytes). 72 | [parameter(ValueFromPipelineByPropertyName=$true)] 73 | [int]$Truncate, 74 | 75 | # Indicates what view should be used to present the data. 76 | [ValidateSet("Default", "Payload", "Details")] 77 | [string]$View = "Default", 78 | 79 | 80 | # UserName to use when logging to RabbitMq server. 81 | [Parameter(Mandatory=$true, ParameterSetName='login')] 82 | [string]$UserName, 83 | 84 | # Password to use when logging to RabbitMq server. 85 | [Parameter(Mandatory=$true, ParameterSetName='login')] 86 | [string]$Password, 87 | 88 | # Credentials to use when logging to RabbitMQ server. 89 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 90 | [PSCredential]$Credentials 91 | ) 92 | 93 | Begin 94 | { 95 | $Credentials = NormaliseCredentials 96 | $cnt = 0 97 | } 98 | Process 99 | { 100 | if (-not $VirtualHost) 101 | { 102 | # figure out the Virtual Host value 103 | $p = @{} 104 | $p.Add("Credentials", $Credentials) 105 | if ($ComputerName) { $p.Add("ComputerName", $ComputerName) } 106 | 107 | $queues = Get-RabbitMQQueue @p | ? Name -eq $Name 108 | 109 | if (-not $queues) { return; } 110 | 111 | if (-not $queues.GetType().IsArray) 112 | { 113 | $VirtualHost = $queues.vhost 114 | } else { 115 | $vhosts = $queues | select vhost 116 | $s = $vhosts -join ',' 117 | Write-Error "Queue $Name exists in multiple Virtual Hosts: $($queues.vhost -join ', '). Please specify Virtual Host to use." 118 | } 119 | } 120 | 121 | 122 | [string]$s = "" 123 | if ([bool]$Remove) { $s = "Messages will be removed from the queue." } else {$s = "Messages will be requeued."} 124 | if ($pscmdlet.ShouldProcess("server: $ComputerName/$VirtualHost", "Get $Count message(s) from queue $Name. $s")) 125 | { 126 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/queues/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($Name))/get" 127 | Write-Verbose "Invoking REST API: $url" 128 | 129 | $body = @{ 130 | "count" = $Count 131 | "requeue" = -not [bool]$Remove 132 | "encoding" = $Encoding 133 | } 134 | if ($Truncate) { $body.Add("truncate", $Truncate) } 135 | 136 | $bodyJson = $body | ConvertTo-Json 137 | 138 | Write-Debug "body: $bodyJson" 139 | 140 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Post -ContentType "application/json" -Body $bodyJson 141 | 142 | $result | Add-Member -NotePropertyName "QueueName" -NotePropertyValue $Name 143 | 144 | foreach ($item in $result) 145 | { 146 | $cnt++ 147 | $item | Add-Member -NotePropertyName "no" -NotePropertyValue $cnt 148 | $item | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 149 | $item | Add-Member -NotePropertyName "VirtualHost" -NotePropertyValue $VirtualHost 150 | } 151 | 152 | if ($View) 153 | { 154 | switch ($View.ToLower()) 155 | { 156 | 'payload' 157 | { 158 | SendItemsToOutput $result "RabbitMQ.QueueMessage" | fc 159 | } 160 | 161 | 'details' 162 | { 163 | SendItemsToOutput $result "RabbitMQ.QueueMessage" | ft -View Details 164 | } 165 | 166 | Default { SendItemsToOutput $result "RabbitMQ.QueueMessage" } 167 | } 168 | } 169 | } 170 | } 171 | End 172 | { 173 | Write-Verbose "`r`nGot $cnt messages from queue $Name, vhost $VirtualHost, server: $ComputerName." 174 | } 175 | } 176 | 177 | -------------------------------------------------------------------------------- /GetNode.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets RabbitMQ Nodes. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQNode cmdlet gets nodes in RabbitMQ cluster. 7 | 8 | The cmdlet allows you to show list of cluster nodes or filter them by name using wildcards. 9 | The result may be zero, one or many RabbitMQ.Node objects. 10 | 11 | To get Nodes from remote server you need to provide -ComputerName parameter. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQNode 17 | 18 | This command gets a list of nodes in RabbitMQ cluster. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQNode -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of nodes in the cluster on myrabbitmq.servers.com server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQNode second* 27 | 28 | This command gets a list of nodes in a cluster which name starts with "second". 29 | 30 | .EXAMPLE 31 | Get-RabbitMQNode secondary*, primary 32 | 33 | This command gets cluster nodes which name is either "primary" or starts with "secondary". 34 | 35 | 36 | .EXAMPLE 37 | @("primary", "secondary") | Get-RabbitMQNode 38 | 39 | This command pipes node name filters to Get-RabbitMQNode cmdlet. 40 | 41 | .INPUTS 42 | You can pipe Name to filter the results. 43 | 44 | .OUTPUTS 45 | By default, the cmdlet returns list of RabbitMQ.Node objects which describe cluster nodes. 46 | 47 | .LINK 48 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 49 | #> 50 | function Get-RabbitMQNode 51 | { 52 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 53 | Param 54 | ( 55 | # Name of RabbitMQ Node. 56 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 57 | [Alias("Node", "NodeName")] 58 | [string[]]$Name = "", 59 | 60 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 61 | [parameter(ValueFromPipelineByPropertyName=$true)] 62 | [Alias("HostName", "hn", "cn")] 63 | [string]$ComputerName = $defaultComputerName, 64 | 65 | 66 | # UserName to use when logging to RabbitMq server. 67 | [Parameter(Mandatory=$true, ParameterSetName='login')] 68 | [string]$UserName, 69 | 70 | # Password to use when logging to RabbitMq server. 71 | [Parameter(Mandatory=$true, ParameterSetName='login')] 72 | [string]$Password, 73 | 74 | # Credentials to use when logging to RabbitMQ server. 75 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 76 | [PSCredential]$Credentials 77 | ) 78 | 79 | Begin 80 | { 81 | $Credentials = NormaliseCredentials 82 | } 83 | Process 84 | { 85 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get node(s): $(NamesToString $Name '(all)')")) 86 | { 87 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "nodes" 88 | 89 | $result = ApplyFilter $result 'name' $Name 90 | 91 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 92 | 93 | SendItemsToOutput $result "RabbitMQ.Node" 94 | } 95 | } 96 | End 97 | { 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /GetOverview.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Get overview information about RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQOverview gets overview information about one or more RabbitMQ servers. 7 | 8 | Returned object contains information about RabbitMQ server such as its version, Erlang version, node name, number of exchanges, queues, messages, consumers, connection and channels. It also contains object with server statistics. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | .INPUTS 13 | You can pipe ComputerName to the cmdlet. 14 | 15 | .OUTPUTS 16 | By default, the cmdlet returns list of RabbitMQ.ServerOverview objects which describe RabbitMQ server. 17 | 18 | .EXAMPLE 19 | Get-RabbitMQOverview 20 | 21 | Gets overview information about local RabbitMQ server. 22 | 23 | .EXAMPLE 24 | Get-RabbitMQOverview localhost, 127.0.0.1 25 | 26 | Gets overview information about following servers: localhost and 127.0.0.1. This command can be used to compare different instances. 27 | 28 | .EXAMPLE 29 | @('localhost', '127.0.0.1') | Get-RabbitMQOverview 30 | 31 | This example shows how to pipe list of servers for which to get overview information. In the above example the cmdlet will show information about following servers: localhost and 127.0.0.1. 32 | 33 | .LINK 34 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 35 | #> 36 | function Get-RabbitMQOverview 37 | { 38 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 39 | Param 40 | ( 41 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 42 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 43 | [Alias("cn", "HostName", "ComputerName")] 44 | [string[]]$Name = $defaultComputerName, 45 | 46 | 47 | # UserName to use when logging to RabbitMq server. 48 | [Parameter(Mandatory=$true, ParameterSetName='login')] 49 | [string]$UserName, 50 | 51 | # Password to use when logging to RabbitMq server. 52 | [Parameter(Mandatory=$true, ParameterSetName='login')] 53 | [string]$Password, 54 | 55 | # Credentials to use when logging to RabbitMQ server. 56 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 57 | [PSCredential]$Credentials 58 | ) 59 | 60 | Begin 61 | { 62 | $Credentials = NormaliseCredentials 63 | } 64 | Process 65 | { 66 | if (-not $pscmdlet.ShouldProcess("server $ComputerName", "Get overview: $(NamesToString $Name '(all)')")) 67 | { 68 | foreach ($cn in $Name) 69 | { 70 | Write-Host "Getting overview for server: $cn" 71 | } 72 | return; 73 | } 74 | 75 | foreach ($cn in $Name) 76 | { 77 | $overview = GetItemsFromRabbitMQApi -ComputerName $cn $Credentials "overview" 78 | $overview | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $cn 79 | $overview.PSObject.TypeNames.Insert(0, "RabbitMQ.ServerOverview") 80 | 81 | Write-Output $overview 82 | } 83 | } 84 | End 85 | { 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /GetPermission.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets Permissions for VirtualHost and/or user. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQPermission cmdlet shows permissions users have to work with virtual hosts. 7 | 8 | The cmdlet allows you to show all permissions or filter them by VirtualHost and/or User using wildcards. 9 | The result may be zero, one or many RabbitMQ.Permission objects. 10 | 11 | To get permissions from remote server you need to provide -ComputerName. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQPermission 17 | 18 | Show permissions of all users and all virtual hosts from the local RabbitMQ server. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQPermission -ComputerName myrabbitmq.servers.com 22 | 23 | Show permissions of all users and all virtual hosts from the myrabbitmq.servers.com server RabbitMQ server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQPermission -VirtualHost / -User guest 27 | 28 | List user guest permissions to virtual host /. 29 | 30 | .EXAMPLE 31 | Get-RabbitMQPermission private* 32 | 33 | Show permissions of all users in virtual hosts which name starts with "private". 34 | 35 | .EXAMPLE 36 | Get-RabbitMQPermission private*, public* 37 | 38 | This command gets a list of all Virtual Hosts which name starts with "private" or "public". 39 | 40 | .INPUTS 41 | You can pipe Virtual Host and User names to filter results. 42 | 43 | .OUTPUTS 44 | By default, the cmdlet returns list of RabbitMQ.Permission objects. 45 | 46 | .LINK 47 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 48 | #> 49 | function Get-RabbitMQPermission 50 | { 51 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 52 | Param 53 | ( 54 | # Name of RabbitMQ Virtual Host. 55 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position = 0)] 56 | [Alias("vh")] 57 | [string[]]$VirtualHost = "", 58 | 59 | # Name of RabbitMQ Virtual Host. 60 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position = 1)] 61 | [string[]]$User = "", 62 | 63 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 64 | [parameter(ValueFromPipelineByPropertyName=$true)] 65 | [Alias("HostName", "hn", "cn")] 66 | [string]$ComputerName = $defaultComputerName, 67 | 68 | 69 | # UserName to use when logging to RabbitMq server. 70 | [Parameter(Mandatory=$true, ParameterSetName='login')] 71 | [string]$UserName, 72 | 73 | # Password to use when logging to RabbitMq server. 74 | [Parameter(Mandatory=$true, ParameterSetName='login')] 75 | [string]$Password, 76 | 77 | # Credentials to use when logging to RabbitMQ server. 78 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 79 | [PSCredential]$Credentials 80 | ) 81 | 82 | Begin 83 | { 84 | $Credentials = NormaliseCredentials 85 | } 86 | Process 87 | { 88 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get permission(s) for VirtualHost = $(NamesToString $VirtualHost '(all)') and User = $(NamesToString $User '(all)')")) 89 | { 90 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "permissions" 91 | $result = ApplyFilter $result "vhost" $VirtualHost 92 | $result = ApplyFilter $result "user" $User 93 | 94 | 95 | foreach($i in $result) 96 | { 97 | $i | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 98 | } 99 | 100 | SendItemsToOutput $result "RabbitMQ.Permission" 101 | } 102 | } 103 | End 104 | { 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /GetQueue.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets open RabbitMQ Channels. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQQueue cmdlet gets queues registered with RabbitMQ server. 7 | 8 | The cmdlet allows you to show list of all queues or filter them by name using wildcards. 9 | The result may be zero, one or many RabbitMQ.Queue objects. 10 | 11 | To get Queues from remote server you need to provide -ComputerName parameter. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQQueue 17 | 18 | This command gets a list of all queues reigsters with local RabbitMQ server. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQQueue -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of all queues registerd with myrabbitmq.servers.com server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQQueue services* 27 | 28 | This command gets a list of all queues which name starts with "services". 29 | 30 | .EXAMPLE 31 | Get-RabbitMQQueue -VirtualHost vhost1 32 | 33 | This command gets a list of all queues in Virtual Host "vhost1". 34 | 35 | .EXAMPLE 36 | Get-RabbitMQQueue -NotEmpty 37 | 38 | This command gets a list of all queues having messages. 39 | 40 | .EXAMPLE 41 | Get-RabbitMQQueue -ShowStats 42 | 43 | This command shows queue statistics. 44 | It is equivalent to running Get-RabbitMQQueue | Format-Table -View Stats 45 | 46 | .EXAMPLE 47 | @("services*", "posion*") | Get-RabbitMQQueue 48 | 49 | This command pipes queue name filters to Get-RabbitMQQueue cmdlet. 50 | 51 | .INPUTS 52 | You can pipe queue Name, VirtualHost and ComputerName to filter the results. 53 | 54 | .OUTPUTS 55 | By default, the cmdlet returns list of RabbitMQ.Queue objects which describe RabbitMQ queue. 56 | 57 | .LINK 58 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 59 | #> 60 | function Get-RabbitMQQueue 61 | { 62 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 63 | Param 64 | ( 65 | # Name of RabbitMQ queue. 66 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 67 | [Alias("queue", "QueueName")] 68 | [string[]]$Name = "", 69 | 70 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 71 | [parameter(ValueFromPipelineByPropertyName=$true)] 72 | [Alias("HostName", "hn", "cn")] 73 | [string]$ComputerName = $defaultComputerName, 74 | 75 | # Name of the virtual host to filter channels by. 76 | [parameter(ValueFromPipelineByPropertyName=$true)] 77 | [Alias("vh", "vhost")] 78 | [string]$VirtualHost, 79 | 80 | 81 | # When set then returns only queues which have messages. 82 | [switch]$NotEmpty, 83 | 84 | # When set then displays queue statistics. 85 | [switch]$ShowStats, 86 | 87 | 88 | # UserName to use when logging to RabbitMq server. 89 | [Parameter(Mandatory=$true, ParameterSetName='login')] 90 | [string]$UserName, 91 | 92 | # Password to use when logging to RabbitMq server. 93 | [Parameter(Mandatory=$true, ParameterSetName='login')] 94 | [string]$Password, 95 | 96 | # Credentials to use when logging to RabbitMQ server. 97 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 98 | [PSCredential]$Credentials 99 | ) 100 | 101 | Begin 102 | { 103 | $Credentials = NormaliseCredentials 104 | } 105 | Process 106 | { 107 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get queues(s): $(NamesToString $Name '(all)')")) 108 | { 109 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "queues" 110 | 111 | $result = ApplyFilter $result 'name' $Name 112 | if ($VirtualHost) { $result = ApplyFilter $result 'vhost' $VirtualHost } 113 | 114 | foreach ($item in $result) 115 | { 116 | if ($item.messages -eq $null) { $item | Add-Member -MemberType NoteProperty -Name messages -Value 0 } 117 | if ($item.messages_ready -eq $null) { $item | Add-Member -MemberType NoteProperty -Name messages_ready -Value 0 } 118 | if ($item.messages_unacknowledged -eq $null) { $item | Add-Member -MemberType NoteProperty -Name messages_unacknowledged -Value 0 } 119 | } 120 | 121 | if ($NotEmpty) { 122 | $result = $result | ? messages -ne 0 123 | } 124 | 125 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 126 | 127 | if ($ShowStats) 128 | { 129 | SendItemsToOutput $result "RabbitMQ.Queue" | ft -View Stats 130 | } 131 | else 132 | { 133 | SendItemsToOutput $result "RabbitMQ.Queue" 134 | } 135 | } 136 | } 137 | End 138 | { 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /GetQueueBinding.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets bindings for given RabbitMQ Queue. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQQueueBinding cmdlet gets bindings for given RabbitMQ Queue. 7 | 8 | The cmdlet allows you to show all Bindings for given RabbitMQ Queue. 9 | The result may be zero, one or many RabbitMQ.Connection objects. 10 | 11 | To get Connections from remote server you need to provide -ComputerName parameter. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQQueueBinding vh1 q1 17 | 18 | This command gets a list of bindings for queue named "q1" on virtual host "vh1". 19 | 20 | .EXAMPLE 21 | Get-RabbitMQQueueBinding -VirtualHost vh1 -Name q1 -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of bindings for queue named "q1" on virtual host "vh1" and server myrabbitmq.servers.com. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQQueueBinding vh1 q1,q2,q3 27 | 28 | This command gets a list of bindings for queues named "q1", "q2" and "q3" on virtual host "vh1". 29 | 30 | .INPUTS 31 | You can pipe Name, VirtualHost and ComputerName to this cmdlet. 32 | 33 | .OUTPUTS 34 | By default, the cmdlet returns list of RabbitMQ.QueueBinding objects which describe connections. 35 | 36 | .LINK 37 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 38 | #> 39 | function Get-RabbitMQQueueBinding 40 | { 41 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 42 | Param 43 | ( 44 | # Name of RabbitMQ Queue. 45 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 46 | [Alias("queue", "QueueName")] 47 | [string[]]$Name = "", 48 | 49 | # Name of the virtual host to filter channels by. 50 | [parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)] 51 | [Alias("vh", "vhost")] 52 | [string]$VirtualHost, 53 | 54 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 55 | [parameter(ValueFromPipelineByPropertyName=$true, Position=2)] 56 | [Alias("HostName", "hn", "cn")] 57 | [string]$ComputerName = $defaultComputerName, 58 | 59 | 60 | # UserName to use when logging to RabbitMq server. 61 | [Parameter(Mandatory=$true, ParameterSetName='login')] 62 | [string]$UserName, 63 | 64 | # Password to use when logging to RabbitMq server. 65 | [Parameter(Mandatory=$true, ParameterSetName='login')] 66 | [string]$Password, 67 | 68 | # Credentials to use when logging to RabbitMQ server. 69 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 70 | [PSCredential]$Credentials 71 | ) 72 | 73 | Begin 74 | { 75 | $Credentials = NormaliseCredentials 76 | } 77 | Process 78 | { 79 | if (-not $VirtualHost) 80 | { 81 | # figure out the Virtual Host value 82 | $p = @{} 83 | $p.Add("Credentials", $Credentials) 84 | if ($ComputerName) { $p.Add("ComputerName", $ComputerName) } 85 | 86 | $queues = Get-RabbitMQQueue @p | ? Name -eq $Name 87 | 88 | if (-not $queues) { return; } 89 | 90 | if (-not $queues.GetType().IsArray) 91 | { 92 | $VirtualHost = $queues.vhost 93 | } else { 94 | $vhosts = $queues | select vhost 95 | $s = $vhosts -join ',' 96 | Write-Error "Queue $Name exists in multiple Virtual Hosts: $($queues.vhost -join ', '). Please specify Virtual Host to use." 97 | } 98 | } 99 | 100 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get bindings for queue(s): $(NamesToString $Name '(all)')")) 101 | { 102 | foreach ($n in $Name) 103 | { 104 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "queues/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($n))/bindings" 105 | 106 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 107 | 108 | SendItemsToOutput $result "RabbitMQ.QueueBinding" 109 | } 110 | } 111 | } 112 | End 113 | { 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /GetRabbitMQCredentials.ps1: -------------------------------------------------------------------------------- 1 | function GetRabbitMQCredentials 2 | { 3 | Param 4 | ( 5 | [parameter(Mandatory=$true)] 6 | [string]$userName, 7 | 8 | [parameter(Mandatory=$true)] 9 | [string]$password 10 | ) 11 | 12 | $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force 13 | return New-Object System.Management.Automation.PSCredential ($userName, $secpasswd) 14 | } -------------------------------------------------------------------------------- /GetUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets list of users. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQUser gets list of users registered in RabbitMQ server. 7 | 8 | The result may be zero, one or many RabbitMQ.User objects. 9 | 10 | To get users from remote server you need to provide -ComputerName. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | .EXAMPLE 15 | Get-RabbitMQUser 16 | 17 | Gets list of all users in local RabbitMQ server. 18 | 19 | .EXAMPLE 20 | Get-RabbitMQUser -ComputerName myrabbitmq.servers.com 21 | 22 | Gets list of all users in myrabbitmq.servers.com server. 23 | 24 | .EXAMPLE 25 | Get-RabbitMQUser gu* 26 | 27 | Gets list of all users whose name starts with "gu". 28 | 29 | .EXAMPLE 30 | Get-RabbitMQUser guest, admin 31 | 32 | Gets data for users guest and admin. 33 | 34 | .EXAMPLE 35 | Get-RabbitMQUser -View Flat 36 | 37 | Gets flat list of all users. This view doesn't group users by ComputerName as the default view do. 38 | 39 | .INPUTS 40 | You can pipe Names and ComputerNames to filter results. 41 | 42 | .OUTPUTS 43 | By default, the cmdlet returns list of RabbitMQ.User objects which describe user. 44 | 45 | .LINK 46 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 47 | #> 48 | function Get-RabbitMQUser 49 | { 50 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, PositionalBinding=$false)] 51 | Param 52 | ( 53 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 54 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 55 | [string[]]$Name, 56 | 57 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 58 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] 59 | [Alias("cn", "HostName")] 60 | [string]$ComputerName = $defaultComputerName, 61 | 62 | [ValidateSet("Default", "Flat")] 63 | [string]$View, 64 | 65 | # UserName to use when logging to RabbitMq server. Default value is guest. 66 | [Parameter(Mandatory=$true, ParameterSetName='login')] 67 | [string]$UserName, 68 | 69 | # Password to use when logging to RabbitMq server. Default value is guest. 70 | [Parameter(Mandatory=$true, ParameterSetName='login')] 71 | [string]$Password, 72 | 73 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 74 | [PSCredential]$Credentials 75 | ) 76 | 77 | Begin 78 | { 79 | $Credentials = NormaliseCredentials 80 | } 81 | Process 82 | { 83 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get user(s)")) 84 | { 85 | $result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "users" 86 | $result = ApplyFilter $result 'name' $Name 87 | $result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 88 | 89 | if (-not $View) { SendItemsToOutput $result "RabbitMQ.User" } 90 | else { SendItemsToOutput $result "RabbitMQ.User" | ft -View $View } 91 | } 92 | } 93 | End 94 | { 95 | } 96 | } -------------------------------------------------------------------------------- /GetVirtualHost.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Gets Virtual Hosts registered with the server. 4 | 5 | .DESCRIPTION 6 | The Get-RabbitMQVirtualHost gets Virtual Hosts registered with RabbitMQ server. 7 | 8 | The cmdlet allows you to show all Virtual Hosts or filter them by name using wildcards. 9 | The result may be zero, one or many RabbitMQ.VirtualHost objects. 10 | 11 | To get Virtual Hosts from remote server you need to provide -ComputerName. 12 | 13 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 14 | 15 | .EXAMPLE 16 | Get-RabbitMQVirtualHost 17 | 18 | This command gets a list of all Virtual Hosts registered with RabbitMQ on local server. 19 | 20 | .EXAMPLE 21 | Get-RabbitMQVirtualHost -ComputerName myrabbitmq.servers.com 22 | 23 | This command gets a list of all Virtual Hosts registered with RabbitMQ on myrabbitmq.servers.com server. 24 | 25 | .EXAMPLE 26 | Get-RabbitMQVirtualHost private* 27 | 28 | This command gets a list of all Virtual Hosts which name starts with "private". 29 | 30 | .EXAMPLE 31 | Get-RabbitMQVirtualHost private*, public* 32 | 33 | This command gets a list of all Virtual Hosts which name starts with "private" or "public". 34 | 35 | .EXAMPLE 36 | Get-RabbitMQVirtualHost private*, public* 37 | 38 | This command gets a list of all Virtual Hosts which name starts with "private" or "public". 39 | 40 | .EXAMPLE 41 | Get-RabbitMQVirtualHost marketing_private | select * 42 | 43 | This command selects all properties for given Virtual Host. 44 | 45 | .EXAMPLE 46 | @("private*", "*public") | Get-RabbitMQVirtualHost 47 | 48 | This command pipes name filters to Get-RabbitMQVirtualHost cmdlet. 49 | 50 | .INPUTS 51 | You can pipe Virtual Host names to filter results. 52 | 53 | .OUTPUTS 54 | By default, the cmdlet returns list of RabbitMQ.VirtualHost objects which describe Virtual Hosts. 55 | 56 | .LINK 57 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 58 | #> 59 | function Get-RabbitMQVirtualHost 60 | { 61 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='None')] 62 | Param 63 | ( 64 | # Name of RabbitMQ Virtual Host. 65 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position = 0)] 66 | [Alias("vh", "VirtualHost")] 67 | [string[]]$Name = "", 68 | 69 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 70 | [parameter(ValueFromPipelineByPropertyName=$true)] 71 | [Alias("HostName", "hn", "cn")] 72 | [string]$ComputerName = $defaultComputerName, 73 | 74 | 75 | # UserName to use when logging to RabbitMq server. 76 | [Parameter(Mandatory=$true, ParameterSetName='login')] 77 | [string]$UserName, 78 | 79 | # Password to use when logging to RabbitMq server. 80 | [Parameter(Mandatory=$true, ParameterSetName='login')] 81 | [string]$Password, 82 | 83 | # Credentials to use when logging to RabbitMQ server. 84 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 85 | [PSCredential]$Credentials 86 | ) 87 | 88 | Begin 89 | { 90 | $Credentials = NormaliseCredentials 91 | } 92 | Process 93 | { 94 | if ($pscmdlet.ShouldProcess("server $ComputerName", "Get vhost(s): $(NamesToString $Name '(all)')")) 95 | { 96 | $vhosts = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "vhosts" 97 | $result = ApplyFilter $vhosts "name" $Name 98 | 99 | foreach($i in $result) 100 | { 101 | $i | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName 102 | } 103 | 104 | SendItemsToOutput $result "RabbitMQ.VirtualHost" 105 | } 106 | } 107 | End 108 | { 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Invoke_RestMethodProxy.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-RestMethod 2 | { 3 | [CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=217034')] 4 | param( 5 | [Microsoft.PowerShell.Commands.WebRequestMethod] 6 | ${Method}, 7 | 8 | [Parameter(Mandatory=$true, Position=0)] 9 | [ValidateNotNullOrEmpty()] 10 | [uri] 11 | ${Uri}, 12 | 13 | [Microsoft.PowerShell.Commands.WebRequestSession] 14 | ${WebSession}, 15 | 16 | [Alias('SV')] 17 | [string] 18 | ${SessionVariable}, 19 | 20 | [pscredential] 21 | ${Credential}, 22 | 23 | [switch] 24 | ${UseDefaultCredentials}, 25 | 26 | [ValidateNotNullOrEmpty()] 27 | [string] 28 | ${CertificateThumbprint}, 29 | 30 | [ValidateNotNull()] 31 | [System.Security.Cryptography.X509Certificates.X509Certificate] 32 | ${Certificate}, 33 | 34 | [string] 35 | ${UserAgent}, 36 | 37 | [switch] 38 | ${DisableKeepAlive}, 39 | 40 | [int] 41 | ${TimeoutSec}, 42 | 43 | [System.Collections.IDictionary] 44 | ${Headers}, 45 | 46 | [ValidateRange(0, 2147483647)] 47 | [int] 48 | ${MaximumRedirection}, 49 | 50 | [uri] 51 | ${Proxy}, 52 | 53 | [pscredential] 54 | ${ProxyCredential}, 55 | 56 | [switch] 57 | ${ProxyUseDefaultCredentials}, 58 | 59 | [Parameter(ValueFromPipeline=$true)] 60 | [System.Object] 61 | ${Body}, 62 | 63 | [string] 64 | ${ContentType}, 65 | 66 | [ValidateSet('chunked','compress','deflate','gzip','identity')] 67 | [string] 68 | ${TransferEncoding}, 69 | 70 | [string] 71 | ${InFile}, 72 | 73 | [string] 74 | ${OutFile}, 75 | 76 | [switch] 77 | ${PassThru}, 78 | 79 | [switch] 80 | ${AllowEscapedDotsAndSlashes}) 81 | 82 | begin 83 | { 84 | try { 85 | $outBuffer = $null 86 | if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) 87 | { 88 | $PSBoundParameters['OutBuffer'] = 1 89 | } 90 | 91 | $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Invoke-RestMethod', [System.Management.Automation.CommandTypes]::Cmdlet) 92 | 93 | # check whether need to disable UnEscapingDotsAndSlases on UriParser 94 | $requiresDisableUnEscapingDotsAndSlashes = ($AllowEscapedDotsAndSlashes -and $Uri.OriginalString -match '%2f') 95 | # remove additional proxy parameter to prevent original function from failing 96 | if($PSBoundParameters['AllowEscapedDotsAndSlashes']) { $null = $PSBoundParameters.Remove('AllowEscapedDotsAndSlashes') } 97 | 98 | $scriptCmd = {& $wrappedCmd @PSBoundParameters } 99 | $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) 100 | $steppablePipeline.Begin($PSCmdlet) 101 | } catch { 102 | throw 103 | } 104 | } 105 | 106 | process 107 | { 108 | try { 109 | # Disable UnEscapingDotsAndSlashes on UriParser when necessary 110 | if ($requiresDisableUnEscapingDotsAndSlashes) { 111 | PreventUnEscapeDotsAndSlashesOnUri 112 | } 113 | 114 | $steppablePipeline.Process($_) 115 | } 116 | finally { 117 | # Restore UnEscapingDotsAndSlashes on UriParser when necessary 118 | if ($requiresDisableUnEscapingDotsAndSlashes) { 119 | RestoreUriParserFlags 120 | } 121 | } 122 | } 123 | 124 | end 125 | { 126 | try { 127 | $steppablePipeline.End() 128 | } catch { 129 | throw 130 | } 131 | } 132 | } 133 | <# 134 | 135 | .ForwardHelpTargetName Invoke-RestMethod 136 | .ForwardHelpCategory Cmdlet 137 | 138 | #> 139 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Mariusz Wojcik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MoveMessage.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Moves messages from one RabbitMQ Queue to another. 4 | 5 | .DESCRIPTION 6 | The Move-RabbitMQMessage cmdlet allows to move messages from one RabbitMQ queue to another. 7 | Both source and destination queues must be in the same Virtual Host. 8 | The "exchange" and "routing_key" properties on moved messages will ba changed. 9 | 10 | Moving messages is done by publishing source message on the destination queue and removing it from source queue. 11 | 12 | The cmdlet is not designed to be used on sensitive data. 13 | 14 | WARNING 15 | This operation is not transactional and may result in not all messages being moved or some messages being duplicated. 16 | Also, if there are new messages published to the source queue or messages are consumed, then the operation may fail with unexpected result. 17 | Because of the nature of moving messages, this operation may change order of messages in the destination queue. 18 | 19 | 20 | To move messages on remote server you need to provide -ComputerName parameter. 21 | 22 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 23 | 24 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 25 | 26 | .EXAMPLE 27 | Move-RabbitMQMessage vh1 q1 q2 28 | 29 | Moves all messages from q1 to q2 on Virtual Host vh1. 30 | 31 | .EXAMPLE 32 | Move-RabbitMQMessage vh1 q1 q2 5 33 | 34 | Moves first 5 messages from q1 to q2 on Virtual Host vh1. 35 | 36 | .EXAMPLE 37 | Move-RabbitMQMessage -VirtualHost vh1 -$SourceQueueName q1 -$DestinationQueueName q2 -Count 5 38 | 39 | Moves first 5 messages from q1 to q2 on Virtual Host vh1. 40 | 41 | .INPUTS 42 | 43 | .LINK 44 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 45 | #> 46 | function Move-RabbitMQMessage 47 | { 48 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact='High')] 49 | Param 50 | ( 51 | # Name of the virtual host to filter channels by. 52 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 53 | [Alias("vh", "vhost")] 54 | [string]$VirtualHost, 55 | 56 | # Name of RabbitMQ Queue from which messages should be copied. 57 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 58 | [Alias("from", "fromQueue")] 59 | [string]$SourceQueueName, 60 | 61 | # Name of RabbitMQ Queue to which messages should be copied. 62 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 63 | [Alias("to", "toQueue")] 64 | [string]$DestinationQueueName, 65 | 66 | # If specified, gives the number of messages to copy. 67 | [parameter(ValueFromPipelineByPropertyName=$true, Position=3)] 68 | [int]$Count, 69 | 70 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 71 | [parameter(ValueFromPipelineByPropertyName=$true, Position=4)] 72 | [Alias("HostName", "hn", "cn")] 73 | [string]$ComputerName = $defaultComputerName, 74 | 75 | 76 | # UserName to use when logging to RabbitMq server. 77 | [Parameter(Mandatory=$true, ParameterSetName='login')] 78 | [string]$UserName, 79 | 80 | # Password to use when logging to RabbitMq server. 81 | [Parameter(Mandatory=$true, ParameterSetName='login')] 82 | [string]$Password, 83 | 84 | # Credentials to use when logging to RabbitMQ server. 85 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 86 | [PSCredential]$Credentials 87 | ) 88 | 89 | Begin 90 | { 91 | $Credentials = NormaliseCredentials 92 | $cnt = 0 93 | 94 | $exchange = Get-RabbitMQQueueBinding -VirtualHost $VirtualHost -Name $DestinationQueueName -Credentials $Credentials | ? source -ne "" | select -First 1 95 | } 96 | Process 97 | { 98 | $s = @{$true=$Count;$false='all'}[$Count -gt 0] 99 | if ($pscmdlet.ShouldProcess("server: $ComputerName/$VirtualHost", "Move $s messages from queue $SourceQueueName to queue $DestinationQueueName.")) 100 | { 101 | $m = Get-RabbitMQMessage -Credentials $Credentials -VirtualHost $VirtualHost -Name $SourceQueueName 102 | $c = $m.message_count + 1 103 | 104 | if ($Count -eq 0 -or $Count -gt $c ) { $Count = $c } 105 | Write-Verbose "There are $Count messages to be copied." 106 | 107 | for ($i = 1; $i -le $Count; $i++) 108 | { 109 | # get message to be copies, but do not remove it from the server yet. 110 | $m = Get-RabbitMQMessage -Credentials $Credentials -VirtualHost $VirtualHost -Name $SourceQueueName 111 | 112 | # publish message to copying exchange, this will publish it onto dest queue as well as src queue. 113 | Add-RabbitMQMessage -Credentials $Credentials -VirtualHost $VirtualHost -ExchangeName $exchange.source -RoutingKey $exchange.routing_key -Payload $m.payload -Properties $m.properties 114 | 115 | # remove message from src queue. It has been published step earlier. 116 | $m = Get-RabbitMQMessage -Credentials $Credentials -VirtualHost $VirtualHost -Name $SourceQueueName -Remove 117 | 118 | Write-Verbose "published message $i out of $Count" 119 | $cnt++ 120 | } 121 | } 122 | } 123 | End 124 | { 125 | Write-Verbose "`r`nMoved $cnt messages from queue $SourceQueueName to queue $DestinationQueueName." 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /NamesToString.ps1: -------------------------------------------------------------------------------- 1 | function NamesToString 2 | { 3 | Param 4 | ( 5 | [string[]]$name, 6 | [string]$altText = "" 7 | ) 8 | 9 | if (-not $name) { return $altText } 10 | 11 | return $name -join ';' 12 | } -------------------------------------------------------------------------------- /NormaliseCredentials.ps1: -------------------------------------------------------------------------------- 1 | function NormaliseCredentials() 2 | { 3 | switch ($PsCmdlet.ParameterSetName) 4 | { 5 | "defaultLogin" { return GetRabbitMqCredentials $defaultUserName $defaultPassword } 6 | "login" { return GetRabbitMqCredentials $UserName $Password } 7 | "cred" { return $Credentials } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /PreventUnEscapeDotsAndSlashesOnUri.ps1: -------------------------------------------------------------------------------- 1 | if (-not $UnEscapeDotsAndSlashes) { Set-Variable -Scope Script -name UnEscapeDotsAndSlashes -value 0x2000000 } 2 | 3 | function GetUriParserFlags 4 | { 5 | 6 | $getSyntax = [System.UriParser].GetMethod("GetSyntax", 40) 7 | $flags = [System.UriParser].GetField("m_Flags", 36) 8 | 9 | $parser = $getSyntax.Invoke($null, "http") 10 | return $flags.GetValue($parser) 11 | } 12 | 13 | function SetUriParserFlags([int]$newValue) 14 | { 15 | $getSyntax = [System.UriParser].GetMethod("GetSyntax", 40) 16 | $flags = [System.UriParser].GetField("m_Flags", 36) 17 | 18 | $parser = $getSyntax.Invoke($null, "http") 19 | $flags.SetValue($parser, $newValue) 20 | } 21 | 22 | function PreventUnEscapeDotsAndSlashesOnUri 23 | { 24 | if (-not $uriUnEscapesDotsAndSlashes) { return } 25 | 26 | Write-Verbose "Switching off UnEscapesDotsAndSlashes flag on UriParser." 27 | 28 | $newValue = $defaultUriParserFlagsValue -bxor $UnEscapeDotsAndSlashes 29 | 30 | SetUriParserFlags $newValue 31 | } 32 | 33 | function RestoreUriParserFlags 34 | { 35 | if (-not $uriUnEscapesDotsAndSlashes) { return } 36 | 37 | Write-Verbose "Restoring UriParser flags - switching on UnEscapesDotsAndSlashes flag." 38 | 39 | try 40 | { 41 | SetUriParserFlags $defaultUriParserFlagsValue 42 | } 43 | catch [System.Exception] 44 | { 45 | Write-Error "Failed to restore UriParser flags. This may cause your scripts to behave unexpectedly. You can find more at get-help about_UnEsapingDotsAndSlashes." 46 | throw 47 | } 48 | } 49 | 50 | if (-not $defaultUriParserFlagsValue) { Set-Variable -Scope Script -name defaultUriParserFlagsValue -value (GetUriParserFlags) } 51 | if (-not $uriUnEscapesDotsAndSlashes) { Set-Variable -Scope Script -name uriUnEscapesDotsAndSlashes -value (($defaultUriParserFlagsValue -band $UnEscapeDotsAndSlashes) -eq $UnEscapeDotsAndSlashes) } 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RabbitMQTools 2 | ============= 3 | 4 | This module provides set of cmdlets to manage RabbitMQ. 5 | 6 | ## Getting started 7 | 8 | Clone the repository to your local drive and then import it to PowerShell 9 | 10 | cd .\path_to_module_directy 11 | Import-Module RabbitMQTools 12 | 13 | Alternatively, if you want the module to be imported automatically every time new PowerShell session is started then clone the repository to your modules path. To find the path run 14 | 15 | $env:PSModulePath -split ';' 16 | 17 | and clone the repository to the path under your documents. 18 | 19 | ## What can I do with it? 20 | 21 | There is a set of cmdlets to manage the server, such as: 22 | 23 | - Get-RabbitMQOverview 24 | - Get-RabbitMQNode 25 | - Get-RabbitMQConnection 26 | - Get-RabbitMQChannel 27 | - Get-RabbitMQVirtualHost, Add-RabbitMQVirtualHost, Remove-RabbitMQVirtualHost 28 | - Get-RabbitMQExchage, Add-RabbitMQExchange, Remove-RabbitMQExchange 29 | - Get-RbbitMQQueue, Add-RabbitMQQueue, Remove-RabbitMQQueue 30 | - Get-RabbitMQMessage 31 | 32 | To learn more about a cmdlet, or to see some examples run Get-Help cmdlet_name 33 | -------------------------------------------------------------------------------- /RabbitMQTools.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mariuszwojcik/RabbitMQTools/c183e835a9f868c3c4ad987dddb2c012a4e64f80/RabbitMQTools.psd1 -------------------------------------------------------------------------------- /RabbitMQTools.psm1: -------------------------------------------------------------------------------- 1 | #if (Test-Path Function:TabExpansion2) { 2 | # $OldTabExpansion = Get-Content Function:TabExpansion2 3 | #} 4 | # 5 | #$Module = $MyInvocation.MyCommand.ScriptBlock.Module 6 | #$Module.OnRemove = { 7 | # 8 | # #$Function:TabExpansion2 = $OldTabExpansion 9 | # 10 | # Remove-Variable -name 'UnEscapeDotsAndSlashes' -Force 11 | # Remove-Variable -name 'defaultUriParserFlagsValue' -Force 12 | # Remove-Variable -name 'uriUnEscapesDotsAndSlashes' -Force 13 | #} 14 | 15 | 16 | Register-RabbitMQServer 'localhost' -WarningAction SilentlyContinue 17 | 18 | # Aliases 19 | New-Alias -Name grvh -value Get-RabbitMQVirtualHost -Description "Gets RabbitMQ's Virutal Hosts" 20 | New-Alias -Name getvhost -value Get-RabbitMQVirtualHost -Description "Gets RabbitMQ's Virutal Hosts" 21 | New-Alias -Name arvh -value Add-RabbitMQVirtualHost -Description "Adds RabbitMQ's Virutal Hosts" 22 | New-Alias -Name addvhost -value Add-RabbitMQVirtualHost -Description "Adds RabbitMQ's Virutal Hosts" 23 | New-Alias -Name rrvh -value Remove-RabbitMQVirtualHost -Description "Removes RabbitMQ's Virutal Hosts" 24 | New-Alias -Name delvhost -value Remove-RabbitMQVirtualHost -Description "Removes RabbitMQ's Virutal Hosts" 25 | 26 | New-Alias -Name gre -value Get-RabbitMQExchange -Description "Gets RabbitMQ's Exchages" 27 | 28 | New-Alias -Name grq -value Get-RabbitMQQueue -Description "Gets RabbitMQ's Queues" 29 | New-Alias -Name getqueue -value Get-RabbitMQQueue -Description "Gets RabbitMQ's Queues" 30 | New-Alias -Name arq -value Add-RabbitMQQueue -Description "Adds RabbitMQ's Queues" 31 | New-Alias -Name addqueue -value Add-RabbitMQQueue -Description "Adds RabbitMQ's Queues" 32 | New-Alias -Name rrq -value Remove-RabbitMQQueue -Description "Removes RabbitMQ's Queues" 33 | New-Alias -Name delqueue -value Remove-RabbitMQQueue -Description "Removes RabbitMQ's Queues" 34 | New-Alias -Name getqueuebinding -value Get-RabbitMQQueueBinding -Description "Gets bindings for RabbitMQ Queues" 35 | New-Alias -Name addqueuebinding -value Add-RabbitMQQueueBinding -Description "Adds bindings betwen RabbitMQ exchange and queue" 36 | 37 | New-Alias -Name getmessage -value Get-RabbitMQMessage -Description "Gets messages from RabbitMQ queue" 38 | 39 | Export-ModuleMember -Alias * 40 | 41 | # Modules 42 | Export-ModuleMember -Function Get-RabbitMQVirtualHost, Add-RabbitMQVirtualHost, Remove-RabbitMQVirtualHost 43 | Export-ModuleMember -Function Get-RabbitMQOverview 44 | Export-ModuleMember -Function Get-RabbitMQExchange, Add-RabbitMQExchange, Remove-RabbitMQExchange 45 | 46 | Export-ModuleMember -Function Get-RabbitMQConnection, Remove-RabbitMQConnection 47 | Export-ModuleMember -Function Get-RabbitMQNode 48 | Export-ModuleMember -Function Get-RabbitMQChannel 49 | 50 | Export-ModuleMember -Function Get-RabbitMQQueue, Add-RabbitMQQueue, Remove-RabbitMQQueue, Get-RabbitMQQueueBinding, Add-RabbitMQQueueBinding, Remove-RabbitMQQueueBinding 51 | 52 | Export-ModuleMember -Function Get-RabbitMQMessage, Add-RabbitMQMessage, Copy-RabbitMQMessage, Move-RabbitMQMessage, Clear-RabbitMQQueue 53 | 54 | Export-ModuleMember -Function Register-RabbitMQServer, Unregister-RabbitMQServer 55 | 56 | Export-ModuleMember -Function Get-RabbitMQUser, Add-RabbitMQUser, Remove-RabbitMQUser, Set-RabbitMQUser 57 | 58 | Export-ModuleMember -Function Get-RabbitMQPermission, Add-RabbitMQPermission, Set-RabbitMQPermission, Remove-RabbitMQPermission 59 | -------------------------------------------------------------------------------- /RegisterServer.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Registers RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | Register-RabbitMQ server cmdlet allows to add RabbitMQ server to the tab completition list for ComputerName. 7 | 8 | .EXAMPLE 9 | Register-RabbitMQServer '127.0.0.1' 10 | 11 | Adds server 127.0.0.1 to auto completition list for ComputerName parameter. 12 | 13 | .EXAMPLE 14 | Register-RabbitMQServer '127.0.0.1' 'My local PC' 15 | 16 | Adds server 127.0.0.1 to auto completition list for ComputerName parameter. The text 'My local PC' will be used as a tooltip. 17 | #> 18 | function Register-RabbitMQServer 19 | { 20 | [CmdletBinding()] 21 | Param 22 | ( 23 | # Name of the RabbitMQ server to be registered. 24 | [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 25 | $ComputerName, 26 | 27 | # Description to be used in tooltip. If not provided then computer name will be used. 28 | [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true, Position=1)] 29 | $Description 30 | ) 31 | 32 | Begin 33 | { 34 | if (-not $global:RabbitMQServers) 35 | { 36 | $global:RabbitMQServers = @() 37 | } 38 | } 39 | Process 40 | { 41 | $obj += $global:RabbitMQServers | ? ListItemText -eq $ComputerName 42 | if (-not $obj) 43 | { 44 | if (-not $Description) { $Description = $ComputerName } 45 | $escapedComputerName = $ComputerName -replace '\[', '``[' -replace '\]', '``]' 46 | $global:RabbitMQServers += New-Object System.Management.Automation.CompletionResult $escapedComputerName, $ComputerName, 'ParameterValue', $Description 47 | } else { 48 | Write-Warning "Server $ComputerName is already registered. If you want to update the entry you need to unregister the server and register it again" 49 | } 50 | } 51 | End 52 | { 53 | } 54 | } -------------------------------------------------------------------------------- /RemoveConnection.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Closes connection to RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQConnection allows for closing connection to the RabbitMQ server. This cmdlet is marked with High impact. 7 | 8 | To close connections to the remote server you need to provide -ComputerName parameter. 9 | 10 | You may pipe an object with names and, optionally, with computer names to close multiple connection. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | .EXAMPLE 15 | Remove-RabbitMQConnection conn1 16 | 17 | This command closes connection to local RabbitMQ server named "conn1". 18 | 19 | .EXAMPLE 20 | Remove-RabbitMQConnection c1, c1 21 | 22 | This command closes connections to local RabbitMQ server named "c1" and "c2". 23 | 24 | .EXAMPLE 25 | Remove-RabbitMQConnection c1 -ComputerName myrabbitmq.servers.com 26 | 27 | This command closes connection c1 to myrabbitmq.servers.com server. 28 | 29 | .EXAMPLE 30 | @("c1", "c2") | Remove-RabbitMQConnection 31 | 32 | This command pipes list of connection to be closed. In the above example two connections named "c1" and "c2" will be closed. 33 | 34 | .EXAMPLE 35 | $a = $( 36 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "c1"} 37 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "c2"} 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "c3"} 39 | ) 40 | 41 | 42 | $a | Remove-RabbitMQConnection 43 | 44 | Above example shows how to pipe both connection name and Computer Name to specify server. 45 | 46 | The above example will close two connection named "c1" and "c2" to local server, and one connection named "c3" to the server 127.0.0.1. 47 | 48 | .INPUTS 49 | You can pipe connection names and optionally ComputerNames to this cmdlet. 50 | 51 | .LINK 52 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 53 | #> 54 | function Remove-RabbitMQConnection 55 | { 56 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 57 | Param 58 | ( 59 | # Name of RabbitMQ connection. 60 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 61 | [Alias("ConnectionName")] 62 | [string[]]$Name = "", 63 | 64 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 65 | [parameter(ValueFromPipelineByPropertyName=$true)] 66 | [Alias("HostName", "hn", "cn")] 67 | [string]$ComputerName = $defaultComputerName, 68 | 69 | 70 | # UserName to use when logging to RabbitMq server. 71 | [Parameter(Mandatory=$true, ParameterSetName='login')] 72 | [string]$UserName, 73 | 74 | # Password to use when logging to RabbitMq server. 75 | [Parameter(Mandatory=$true, ParameterSetName='login')] 76 | [string]$Password, 77 | 78 | # Credentials to use when logging to RabbitMQ server. 79 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 80 | [PSCredential]$Credentials 81 | ) 82 | 83 | Begin 84 | { 85 | $Credentials = NormaliseCredentials 86 | $cnt = 0 87 | } 88 | Process 89 | { 90 | if (-not $pscmdlet.ShouldProcess("server: $ComputerName", "Close connection(s): $(NamesToString $Name '(all)')")) { 91 | foreach ($qn in $Name) 92 | { 93 | Write "Closing connection $qn to server=$ComputerName" 94 | $cnt++ 95 | } 96 | return 97 | } 98 | 99 | foreach($n in $Name) 100 | { 101 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/connections/$([System.Web.HttpUtility]::UrlEncode($n))" 102 | $result = Invoke-RestMethod $url -Credential $Credentials -DisableKeepAlive -ErrorAction Continue -Method Delete 103 | 104 | Write-Verbose "Closed connection $n to server $ComputerName" 105 | $cnt++ 106 | } 107 | } 108 | End 109 | { 110 | if ($cnt > 1) { Write-Verbose "Closed $cnt connection(s)." } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /RemoveExchange.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Removes Exchange from RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQExchange allows for removing exchanges in given RabbitMQ server. This cmdlet is marked with High impact. 7 | 8 | To remove Exchange from remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with names and, optionally, with computer names to remove multiple Exchanges. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Remove-RabbitMQExchange test 18 | 19 | This command removes Exchange named "test" from local RabbitMQ server. 20 | 21 | .EXAMPLE 22 | Remove-RabbitMQExchange e1, e2 23 | 24 | This command removes Exchanges named "e1" and "e2" from local RabbitMQ server. 25 | 26 | .EXAMPLE 27 | Remove-RabbitMQExchange test -ComputerName myrabbitmq.servers.com 28 | 29 | This command removes Exchange named "test" from myrabbitmq.servers.com server. 30 | 31 | .EXAMPLE 32 | @("e1", "e2") | Remove-RabbitMQExchange 33 | 34 | This command pipes list of Exchanges to be removed from the RabbitMQ server. In the above example two Exchanges named "e1" and "e2" will be removed from local RabbitMQ server. 35 | 36 | .EXAMPLE 37 | $a = $( 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "e1"} 39 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "e2"} 40 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "e3"} 41 | ) 42 | 43 | 44 | $a | Remove-RabbitMQExchange 45 | 46 | Above example shows how to pipe both Exchange name and Computer Name to specify server from which the Exchange should be removed. 47 | 48 | In the above example two Exchanges named "e1" and "e2" will be removed from RabbitMQ local server, and one Exchange named "e3" will be removed from the server 127.0.0.1. 49 | 50 | .INPUTS 51 | You can pipe Exchange names and optionally ComputerNames to this cmdlet. 52 | 53 | .LINK 54 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 55 | #> 56 | function Remove-RabbitMQExchange 57 | { 58 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 59 | Param 60 | ( 61 | # Name of RabbitMQ Exchange. 62 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 63 | [Alias("Exchange", "ExchangeName")] 64 | [string[]]$Name, 65 | 66 | # Name of RabbitMQ Virtual Host. 67 | [parameter(ValueFromPipelineByPropertyName=$true)] 68 | [Alias("vh", "vhost")] 69 | [string]$VirtualHost = $defaultVirtualhost, 70 | 71 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 72 | [parameter(ValueFromPipelineByPropertyName=$true)] 73 | [Alias("HostName", "hn", "cn")] 74 | [string]$ComputerName = $defaultComputerName, 75 | 76 | 77 | # UserName to use when logging to RabbitMq server. 78 | [Parameter(Mandatory=$true, ParameterSetName='login')] 79 | [string]$UserName, 80 | 81 | # Password to use when logging to RabbitMq server. 82 | [Parameter(Mandatory=$true, ParameterSetName='login')] 83 | [string]$Password, 84 | 85 | # Credentials to use when logging to RabbitMQ server. 86 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 87 | [PSCredential]$Credentials 88 | ) 89 | 90 | Begin 91 | { 92 | $Credentials = NormaliseCredentials 93 | $cnt = 0 94 | } 95 | Process 96 | { 97 | if ($pscmdlet.ShouldProcess("server: $ComputerName, vhost: $VirtualHost", "Remove exchange(s): $(NamesToString $Name '(all)')")) 98 | { 99 | foreach($n in $Name) 100 | { 101 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/exchanges/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($n))" 102 | 103 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete 104 | 105 | Write-Verbose "Deleted Exchange $n on server $ComputerName, Virtual Host $VirtualHost" 106 | $cnt++ 107 | } 108 | } 109 | } 110 | End 111 | { 112 | if ($cnt -gt 1) { Write-Verbose "Deleted $cnt Exchange(s)." } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /RemovePermission.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Removes permissions to virtual host for a user. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQPermission cmdlet allows to remove user permissions to virtual host. 7 | 8 | To remove permissions to remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Remove-RabbitMQPermission -VirtualHost '/' -User Admin 16 | 17 | Removes permissions for user Admin to default virtual host (/) on local RabbitMQ server. 18 | 19 | .EXAMPLE 20 | Remove-RabbitMQPermission -ComputerName rabbitmq.server.com '/' Admin 21 | 22 | Removes permissions for user Admin to default virtual host (/) on remote RabbitMQ rabbitmq.server.com. 23 | 24 | .INPUTS 25 | You can pipe VirtualHost, User and ComputerName to this cmdlet. 26 | 27 | .LINK 28 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 29 | #> 30 | function Remove-RabbitMQPermission 31 | { 32 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Medium")] 33 | Param 34 | ( 35 | # Virtual host to set permission for. 36 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 37 | [Alias("vhost", "vh")] 38 | [string]$VirtualHost, 39 | 40 | # Name of user to set permission for. 41 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 42 | [string]$User, 43 | 44 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 45 | [parameter(ValueFromPipelineByPropertyName=$true)] 46 | [Alias("HostName", "hn", "cn")] 47 | [string]$ComputerName = $defaultComputerName, 48 | 49 | 50 | # UserName to use when logging to RabbitMq server. 51 | [Parameter(Mandatory=$true, ParameterSetName='login')] 52 | [string]$UserName, 53 | 54 | # Password to use when logging to RabbitMq server. 55 | [Parameter(Mandatory=$true, ParameterSetName='login')] 56 | [string]$Password, 57 | 58 | # Credentials to use when logging to RabbitMQ server. 59 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 60 | [PSCredential]$Credentials 61 | ) 62 | 63 | Begin 64 | { 65 | $Credentials = NormaliseCredentials 66 | 67 | $p = Get-RabbitMQPermission -ComputerName $ComputerName -Credentials $Credentials -VirtualHost $VirtualHost -User $User 68 | if (-not $p) { throw "Permissions to virtual host $VirtualHost for user $User do not exist. To create permissions use Add-RabbitMQPermission cmdlet." } 69 | 70 | $cnt = 0 71 | } 72 | Process 73 | { 74 | if ($pscmdlet.ShouldProcess("server: $ComputerName", "Remove permissions to virtual host $VirtualHost for user $User : $Configure, $Read $Write")) 75 | { 76 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/permissions/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($User))" 77 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete 78 | 79 | Write-Verbose "Removed permissions to $VirtualHost for $User : $Configure, $Read, $Write" 80 | $cnt++ 81 | } 82 | } 83 | End 84 | { 85 | if ($cnt -gt 1) { Write-Verbose "Removed $cnt permissions." } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /RemoveQueue.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Removes Queue from RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQQueue allows for removing queues in given RabbitMQ server. This cmdlet is marked with High impact. 7 | 8 | To remove Queue from remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with names and, optionally, with computer names to remove multiple Queues. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Remove-RabbitMQQueue q1 -VirtualHost vh1 18 | 19 | This command removes Queue named "q1" from virtual host vh1 located in local RabbitMQ server. 20 | 21 | .EXAMPLE 22 | Remove-RabbitMQQueue q1, q2 -VirtualHost vh1 23 | 24 | This command removes Queues named "q1" and "q2" from local RabbitMQ server. 25 | 26 | .EXAMPLE 27 | Remove-RabbitMQQueue test -VirtualHost vh1 -ComputerName myrabbitmq.servers.com 28 | 29 | This command removes Queue named "test" from myrabbitmq.servers.com server. 30 | 31 | .EXAMPLE 32 | @("q1", "q2") | Remove-RabbitMQQueue -VirtualHost vh1 33 | 34 | This command pipes list of Queues to be removed from the RabbitMQ server. In the above example two Queues named "q1" and "q2" will be removed from local RabbitMQ server. 35 | 36 | .EXAMPLE 37 | $a = $( 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "e1"} 39 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "e2"} 40 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "e3"} 41 | ) 42 | 43 | 44 | $a | Remove-RabbitMQQueue 45 | 46 | Above example shows how to pipe both Exchange name and Computer Name to specify server from which the Exchange should be removed. 47 | 48 | In the above example two Exchanges named "e1" and "e2" will be removed from RabbitMQ local server, and one Exchange named "e3" will be removed from the server 127.0.0.1. 49 | 50 | .INPUTS 51 | You can pipe Exchange names and optionally ComputerNames to this cmdlet. 52 | 53 | .LINK 54 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 55 | #> 56 | function Remove-RabbitMQQueue 57 | { 58 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 59 | Param 60 | ( 61 | # Name of RabbitMQ Queue. 62 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 63 | [Alias("queue", "QueueName")] 64 | [string[]]$Name, 65 | 66 | # Name of RabbitMQ Virtual Host. 67 | [parameter(ValueFromPipelineByPropertyName=$true)] 68 | [Alias("vh", "vhost")] 69 | [string]$VirtualHost = $defaultVirtualhost, 70 | 71 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 72 | [parameter(ValueFromPipelineByPropertyName=$true)] 73 | [Alias("HostName", "hn", "cn")] 74 | [string]$ComputerName = $defaultComputerName, 75 | 76 | 77 | # UserName to use when logging to RabbitMq server. 78 | [Parameter(Mandatory=$true, ParameterSetName='login')] 79 | [string]$UserName, 80 | 81 | # Password to use when logging to RabbitMq server. 82 | [Parameter(Mandatory=$true, ParameterSetName='login')] 83 | [string]$Password, 84 | 85 | # Credentials to use when logging to RabbitMQ server. 86 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 87 | [PSCredential]$Credentials 88 | ) 89 | 90 | Begin 91 | { 92 | $Credentials = NormaliseCredentials 93 | $cnt = 0 94 | } 95 | Process 96 | { 97 | if ($pscmdlet.ShouldProcess("server: $ComputerName, vhost: $VirtualHost", "Remove queue(s): $(NamesToString $Name '(all)')")) 98 | { 99 | foreach($n in $Name) 100 | { 101 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/queues/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($n))" 102 | Write-Verbose "Invoking REST API: $url" 103 | 104 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete 105 | 106 | Write-Verbose "Deleted Queue $n on server $ComputerName, Virtual Host $VirtualHost" 107 | $cnt++ 108 | } 109 | } 110 | } 111 | End 112 | { 113 | if ($cnt -gt 1) { Write-Verbose "Deleted $cnt Queue(s)." } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /RemoveQueueBinding.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Removes binding between RabbitMQ Queue and Exchange. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQQueueBinding allows for removing bindings between RabbitMQ queues and exchanges. This cmdlet is marked with High impact. 7 | 8 | To remove Queue binding from remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with names and, optionally, with computer names to remove multiple Queues. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Remove-RabbitMQQueueBinding vh1 e1 q1 'e1-q1' 18 | 19 | This command removes binding "e1-q1" between exchange named "e1" and queue named "q1". The operation is performed on local server in virtual host vh1. 20 | 21 | .EXAMPLE 22 | Remove-RabbitMQQueueBinding vh1 e1 q1 'e1-q1' 127.0.0.1 23 | 24 | This command removes binding "e1-q1" between exchange named "e1" and queue named "q1". The operation is performed on server 127.0.0.1 in default virtual host (/). 25 | 26 | .EXAMPLE 27 | Remove-RabbitMQQueueBinding -ComputerName 127.0.0.0 -VirtualHost vh1 -ExchangeName e1 -QueueName q1 -RoutingKey 'e1-q1' 28 | 29 | This command removes binding "e1-q1" between exchange named "e1" and queue named "q1". The operation is performed on server 127.0.0.1 in default virtual host (/). 30 | 31 | .EXAMPLE 32 | 33 | .INPUTS 34 | 35 | .LINK 36 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 37 | #> 38 | function Remove-RabbitMQQueueBinding 39 | { 40 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 41 | Param 42 | ( 43 | # Name of RabbitMQ Virtual Host. 44 | [parameter(Mandatory = $true, ValueFromPipelineByPropertyName=$true, Position = 0)] 45 | [Alias("vh", "vhost")] 46 | [string]$VirtualHost = $defaultVirtualhost, 47 | 48 | # Name of RabbitMQ Exchange. 49 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 50 | [Alias("exchange")] 51 | [string]$ExchangeName, 52 | 53 | # Name of RabbitMQ Queue. 54 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 55 | [Alias("queue", "QueueName")] 56 | [string]$Name, 57 | 58 | # Routing key. 59 | [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=3)] 60 | [Alias("rk")] 61 | [string]$RoutingKey, 62 | 63 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 64 | [parameter(ValueFromPipelineByPropertyName=$true, Position=4)] 65 | [Alias("HostName", "hn", "cn")] 66 | [string]$ComputerName = $defaultComputerName, 67 | 68 | 69 | # UserName to use when logging to RabbitMq server. 70 | [Parameter(Mandatory=$true, ParameterSetName='login')] 71 | [string]$UserName, 72 | 73 | # Password to use when logging to RabbitMq server. 74 | [Parameter(Mandatory=$true, ParameterSetName='login')] 75 | [string]$Password, 76 | 77 | # Credentials to use when logging to RabbitMQ server. 78 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 79 | [PSCredential]$Credentials 80 | ) 81 | 82 | Begin 83 | { 84 | $Credentials = NormaliseCredentials 85 | $cnt = 0 86 | 87 | } 88 | Process 89 | { 90 | if ($pscmdlet.ShouldProcess("$ComputerName/$VirtualHost", "Remove binding between exchange $ExchangeName and queue $Name")) 91 | { 92 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/bindings/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/e/$([System.Web.HttpUtility]::UrlEncode($ExchangeName))/q/$([System.Web.HttpUtility]::UrlEncode($Name))/$([System.Web.HttpUtility]::UrlEncode($RoutingKey))" 93 | Write-Verbose "Invoking REST API: $url" 94 | 95 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete 96 | 97 | Write-Verbose "Removed binding between exchange $ExchangeName and queue $Name $n on $ComputerName/$VirtualHost" 98 | $cnt++ 99 | } 100 | } 101 | End 102 | { 103 | if ($cnt -gt 1) { Write-Verbose "Unbound $cnt Queues." } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /RemoveUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Removes user from RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQUser cmdlet allows to delete users from RabbitMQ server. 7 | 8 | To remove a user from remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Remove-RabbitMQUser -Name Admin 16 | 17 | Deletes user "Admin"from local RabbitMQ server. 18 | 19 | .EXAMPLE 20 | Remove-RabbitMQUser -ComputerName rabbitmq.server.com Admin 21 | 22 | Deletes user "Admin" from rabbitmq.server.com server. This command uses positional parameters. 23 | 24 | .INPUTS 25 | You can pipe Name and ComputerName to this cmdlet. 26 | 27 | .LINK 28 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 29 | #> 30 | function Remove-RabbitMQUser 31 | { 32 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 33 | Param 34 | ( 35 | # Name of user to delete. 36 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 37 | [string]$Name, 38 | 39 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 40 | [parameter(ValueFromPipelineByPropertyName=$true)] 41 | [Alias("HostName", "hn", "cn")] 42 | [string]$ComputerName = $defaultComputerName, 43 | 44 | 45 | # UserName to use when logging to RabbitMq server. 46 | [Parameter(Mandatory=$true, ParameterSetName='login')] 47 | [string]$UserName, 48 | 49 | # Password to use when logging to RabbitMq server. 50 | [Parameter(Mandatory=$true, ParameterSetName='login')] 51 | [string]$Password, 52 | 53 | # Credentials to use when logging to RabbitMQ server. 54 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 55 | [PSCredential]$Credentials 56 | ) 57 | 58 | Begin 59 | { 60 | $Credentials = NormaliseCredentials 61 | $cnt = 0 62 | } 63 | Process 64 | { 65 | if ($pscmdlet.ShouldProcess("server: $ComputerName", "Delete user $Name")) 66 | { 67 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/users/$([System.Web.HttpUtility]::UrlEncode($Name))" 68 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete -ContentType "application/json" 69 | 70 | Write-Verbose "Deleted user $User" 71 | $cnt++ 72 | } 73 | } 74 | End 75 | { 76 | if ($cnt -gt 1) { Write-Verbose "Deleted $cnt users." } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /RemoveVirtualHost.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Removes Virtual Hosts from RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Remove-RabbitMQVirtualHost allows for removing Virtual Hosts in given RabbitMQ server. This cmdlet is marked with High impact. 7 | 8 | To remove Virtual Hosts from remote server you need to provide -ComputerName. 9 | 10 | You may pipe an object with names and, optionally, with computer names to remove multiple VirtualHosts. For more information how to do that see Examples. 11 | 12 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 13 | 14 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 15 | 16 | .EXAMPLE 17 | Remove-RabbitMQVirtualHost testHost 18 | 19 | This command removes Virtual Host named "testHost" from local RabbitMQ server. 20 | 21 | .EXAMPLE 22 | Remove-RabbitMQVirtualHost VHost1, VHost2 23 | 24 | This command removes Virtual Hosts named "VHost1" and "VHost2" from local RabbitMQ server. 25 | 26 | .EXAMPLE 27 | Remove-RabbitMQVirtualHost testHost -ComputerName myrabbitmq.servers.com 28 | 29 | This command removes Virtual Host named "testHost" from myrabbitmq.servers.com server. 30 | 31 | .EXAMPLE 32 | @("VHost1", "VHost2") | Remove-RabbitMQVirtualHost 33 | 34 | This command pipes list of Virtual Hosts to be removed from the RabbitMQ server. In the above example two Virtual Hosts named "VHost1" and "VHost2" will be removed from local RabbitMQ server. 35 | 36 | .EXAMPLE 37 | $a = $( 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "vh1"} 39 | New-Object -TypeName psobject -Prop @{"ComputerName" = "localhost"; "Name" = "vh2"} 40 | New-Object -TypeName psobject -Prop @{"ComputerName" = "127.0.0.1"; "Name" = "vh3"} 41 | ) 42 | 43 | 44 | $a | Remove-RabbitMQVirtualHost 45 | 46 | Above example shows how to pipe both Virtual Host name and Computer Name to specify server from which the Virtual Host should be removed. 47 | 48 | In the above example two Virtual Hosts named "vh1" and "vh2" will be removed from RabbitMQ local server, and one Virtual Host named "vh3" will be removed from the server 127.0.0.1. 49 | 50 | .INPUTS 51 | You can pipe VirtualHost names and optionally ComputerNames to this cmdlet. 52 | 53 | .LINK 54 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 55 | #> 56 | function Remove-RabbitMQVirtualHost 57 | { 58 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="High")] 59 | Param 60 | ( 61 | # Name of RabbitMQ Virtual Host. 62 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 63 | [Alias("vh", "VirtualHost")] 64 | [string[]]$Name = "", 65 | 66 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 67 | [parameter(ValueFromPipelineByPropertyName=$true, Position=1)] 68 | [Alias("HostName", "hn", "cn")] 69 | [string]$ComputerName = $defaultComputerName, 70 | 71 | 72 | # UserName to use when logging to RabbitMq server. 73 | [Parameter(Mandatory=$true, ParameterSetName='login')] 74 | [string]$UserName, 75 | 76 | # Password to use when logging to RabbitMq server. 77 | [Parameter(Mandatory=$true, ParameterSetName='login')] 78 | [string]$Password, 79 | 80 | # Credentials to use when logging to RabbitMQ server. 81 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 82 | [PSCredential]$Credentials 83 | ) 84 | 85 | Begin 86 | { 87 | $Credentials = NormaliseCredentials 88 | $cnt = 0 89 | } 90 | Process 91 | { 92 | if (-not $pscmdlet.ShouldProcess("server: $ComputerName", "Remove vhost(s): $(NamesToString $Name '(all)')")) { 93 | foreach ($qn in $Name) 94 | { 95 | Write "Deleting Virtual Host(s) $qn (server=$ComputerName)" 96 | $cnt++ 97 | } 98 | return 99 | } 100 | 101 | foreach($n in $Name) 102 | { 103 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/vhosts/$([System.Web.HttpUtility]::UrlEncode($n))" 104 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete -ContentType "application/json" 105 | 106 | Write-Verbose "Removed Virtual Host $n on server $ComputerName" 107 | $cnt++ 108 | } 109 | } 110 | End 111 | { 112 | Write-Verbose "Removed $cnt Virtual Host(s)." 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /SendItemsToOutput.ps1: -------------------------------------------------------------------------------- 1 | function SendItemsToOutput 2 | { 3 | Param 4 | ( 5 | [parameter()] 6 | [PSObject[]]$items, 7 | 8 | [parameter(Mandatory=$true)] 9 | [string[]]$typeName 10 | ) 11 | 12 | foreach ($i in $items) 13 | { 14 | $i.PSObject.TypeNames.Insert(0, $typeName) 15 | Write-Output $i 16 | } 17 | } -------------------------------------------------------------------------------- /SetPermission.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Updates permissions to virtual host for a user. 4 | 5 | .DESCRIPTION 6 | The Set-RabbitMQPermission cmdlet allows to update user permissions to virtual host. 7 | 8 | To update permissions to remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Set-RabbitMQPermission -VirtualHost '/' -User Admin -Configure .* -Read .* -Write .* 16 | 17 | Update configure, read and write permissions for user Admin to default virtual host (/). 18 | 19 | .EXAMPLE 20 | Set-RabbitMQPermission -ComputerName rabbitmq.server.com '/' Admin .* .* .* 21 | 22 | Update configure, read and write permissions for user Admin to default virtual host (/) on server rabbitmq.server.com. This command uses positional parameters. 23 | 24 | .INPUTS 25 | You can pipe VirtualHost, User, Configure, Read, Write and ComputerName to this cmdlet. 26 | 27 | .LINK 28 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 29 | #> 30 | function Set-RabbitMQPermission 31 | { 32 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Medium")] 33 | Param 34 | ( 35 | # Virtual host to set permission for. 36 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 37 | [Alias("vhost", "vh")] 38 | [string]$VirtualHost, 39 | 40 | # Name of user to set permission for. 41 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 42 | [string]$User, 43 | 44 | # Configure permission regexp. 45 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 46 | [string]$Configure, 47 | 48 | # Read permission regexp. 49 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=3)] 50 | [string]$Read, 51 | 52 | # Write permission regexp. 53 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=4)] 54 | [string]$Write, 55 | 56 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 57 | [parameter(ValueFromPipelineByPropertyName=$true)] 58 | [Alias("HostName", "hn", "cn")] 59 | [string]$ComputerName = $defaultComputerName, 60 | 61 | 62 | # UserName to use when logging to RabbitMq server. 63 | [Parameter(Mandatory=$true, ParameterSetName='login')] 64 | [string]$UserName, 65 | 66 | # Password to use when logging to RabbitMq server. 67 | [Parameter(Mandatory=$true, ParameterSetName='login')] 68 | [string]$Password, 69 | 70 | # Credentials to use when logging to RabbitMQ server. 71 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 72 | [PSCredential]$Credentials 73 | ) 74 | 75 | Begin 76 | { 77 | $Credentials = NormaliseCredentials 78 | 79 | $p = Get-RabbitMQPermission -ComputerName $ComputerName -Credentials $Credentials -VirtualHost $VirtualHost -User $User 80 | if (-not $p) { throw "Permissions to virtual host $VirtualHost for user $User do not exist. To create permissions use Add-RabbitMQPermission cmdlet." } 81 | 82 | $cnt = 0 83 | } 84 | Process 85 | { 86 | if ($pscmdlet.ShouldProcess("server: $ComputerName", "Changes permission to virtual host $VirtualHost for user $User : $Configure, $Read $Write")) 87 | { 88 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/permissions/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($User))" 89 | $body = @{ 90 | 'configure' = $Configure 91 | 'read' = $Read 92 | 'write' = $Write 93 | } | ConvertTo-Json 94 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" -Body $body 95 | 96 | Write-Verbose "Changed permission to $VirtualHost for $User : $Configure, $Read, $Write" 97 | $cnt++ 98 | } 99 | } 100 | End 101 | { 102 | if ($cnt -gt 1) { Write-Verbose "Changed $cnt permissions." } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /SetUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds user to RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | The Set-RabbitMQUser cmdlet allows to create new users in RabbitMQ server. 7 | 8 | To add a user to remote server you need to provide -ComputerName. 9 | 10 | The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html 11 | 12 | To support requests using default virtual host (/), the cmdlet will temporarily disable UnEscapeDotsAndSlashes flag on UriParser. For more information check get-help about_UnEsapingDotsAndSlashes. 13 | 14 | .EXAMPLE 15 | Set-RabbitMQUser -Name Admin -NewPassword p4ssw0rd -Tag administrator 16 | 17 | Create new user with name Admin having administrator tags set. User is added to local RabbitMQ server. 18 | 19 | .EXAMPLE 20 | Set-RabbitMQUser -ComputerName rabbitmq.server.com Admin p4ssw0rd administrator 21 | 22 | Create new user with name "Admin", password "p4ssw0rd" having "administrator" tags set. User is added to rabbitmq.server.com server. This command uses positional parameters. 23 | Note that password for new user is specified as -NewPassword parameter and not -Password parameter, which is used for authorisation to the server. 24 | 25 | .INPUTS 26 | You can pipe Name, NewPassword, Tags and ComputerName to this cmdlet. 27 | 28 | .LINK 29 | https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin. 30 | #> 31 | function Set-RabbitMQUser 32 | { 33 | [CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, ConfirmImpact="Medium")] 34 | Param 35 | ( 36 | # Name of user to update. 37 | [parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 38 | [string]$Name, 39 | 40 | # New password for user. 41 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=1)] 42 | [string]$NewPassword, 43 | 44 | # Comma-separated list of user tags. 45 | [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=2)] 46 | [ValidateSet("administrator", "monitoring", "policymaker", "management")] 47 | [string[]]$Tag, 48 | 49 | # Name of the computer hosting RabbitMQ server. Defalut value is localhost. 50 | [parameter(ValueFromPipelineByPropertyName=$true)] 51 | [Alias("HostName", "hn", "cn")] 52 | [string]$ComputerName = $defaultComputerName, 53 | 54 | 55 | # UserName to use when logging to RabbitMq server. 56 | [Parameter(Mandatory=$true, ParameterSetName='login')] 57 | [string]$UserName, 58 | 59 | # Password to use when logging to RabbitMq server. 60 | [Parameter(Mandatory=$true, ParameterSetName='login')] 61 | [string]$Password, 62 | 63 | # Credentials to use when logging to RabbitMQ server. 64 | [Parameter(Mandatory=$true, ParameterSetName='cred')] 65 | [PSCredential]$Credentials 66 | ) 67 | 68 | Begin 69 | { 70 | $Credentials = NormaliseCredentials 71 | 72 | $user = Get-RabbitMQUser -Credentials $Credentials -ComputerName $ComputerName -Name $Name 73 | if (-not $user) { throw "User $Name doesn't exist in server $ComputerName" } 74 | 75 | $cnt = 0 76 | } 77 | Process 78 | { 79 | if ($pscmdlet.ShouldProcess("server: $ComputerName", $(GetShouldProcessText))) 80 | { 81 | $url = "http://$([System.Web.HttpUtility]::UrlEncode($ComputerName)):15672/api/users/$([System.Web.HttpUtility]::UrlEncode($Name))" 82 | $body = @{} 83 | 84 | if ($NewPassword) { $body.Add("password", $NewPassword) } 85 | if ($Tag) { $body.Add("tags", $Tag -join ',') } else { $body.Add("tags", $user.tags) } 86 | $bodyJson = $body | ConvertTo-Json 87 | $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Put -ContentType "application/json" -Body $bodyJson 88 | 89 | Write-Verbose "Update user $User" 90 | $cnt++ 91 | } 92 | } 93 | End 94 | { 95 | if ($cnt -gt 1) { Write-Verbose "Updated $cnt new users." } 96 | } 97 | } 98 | 99 | function GetShouldProcessText 100 | { 101 | $str = "Update " 102 | if ($NewPassword -and $Tags) { $str += "password and tags" } 103 | if ($NewPassword) { $str += "password " } 104 | if ($Tag) { $str += "tags" } 105 | 106 | $str += " for user $user." 107 | 108 | if ($Tag) { $str += "New tags: $Tag" } 109 | 110 | return $str 111 | } 112 | -------------------------------------------------------------------------------- /TabExpansions.ps1: -------------------------------------------------------------------------------- 1 | $computerNameCompletion_Process = { 2 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 3 | 4 | $global:RabbitMQServers 5 | } 6 | 7 | $virtualHostCompletion_Process = { 8 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 9 | 10 | $parms = @{} 11 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 12 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 13 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 14 | 15 | Get-RabbitMQVirtualHost @parms | where name -like "$wordToComplete*" | select name | ForEach-Object { 16 | $vhname = @{$true="Default"; $false= $_.name}[$_.name -eq "/"] 17 | $cname = @{$true="localhost"; $false = $fakeBoundParameter.ComputerName}[$fakeBoundParameter.ComputerName -eq $null] 18 | $tooltip = "$vhname on $cname." 19 | 20 | createCompletionResult $_.name $_.name $tooltip 21 | } 22 | } 23 | 24 | $exchangeCompletion_Process = { 25 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 26 | 27 | $parms = @{} 28 | if ($fakeBoundParameter.VirtualHost) { $parms.Add("VirtualHost", $fakeBoundParameter.VirtualHost) } 29 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 30 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 31 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 32 | 33 | Get-RabbitMQExchange @parms | where name -like "$wordToComplete*" | select name | ForEach-Object { 34 | $ename = @{$true="(AMQP default)"; $false=$_.name}[$_.name -eq ""] 35 | $vhname = @{$true="[default]"; $false= $fakeBoundParameter.VirtualHost}[$fakeBoundParameter.VirtualHost -eq "/"] 36 | $cname = @{$true="localhost"; $false = $fakeBoundParameter.ComputerName}[$fakeBoundParameter.ComputerName -eq $null] 37 | $tooltip = "$ename on $cname/$vhname." 38 | 39 | createCompletionResult $ename $ename $tooltip 40 | } 41 | } 42 | 43 | $connectionCompletion_Process = { 44 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 45 | 46 | $parms = @{} 47 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 48 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 49 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 50 | 51 | Get-RabbitMQConnection @parms | where name -like "$wordToComplete*" | select name | ForEach-Object { 52 | $cname = @{$true="localhost"; $false = $fakeBoundParameter.ComputerName}[$fakeBoundParameter.ComputerName -eq $null] 53 | $tooltip = "$_.name on $cname." 54 | 55 | createCompletionResult $_.name $_.name $tooltip 56 | } 57 | } 58 | 59 | $nodeCompletion_Process = { 60 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 61 | 62 | $parms = @{} 63 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 64 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 65 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 66 | 67 | Get-RabbitMQNode @parms | where name -like "$wordToComplete*" | select name | ForEach-Object { 68 | $cname = @{$true="localhost"; $false = $fakeBoundParameter.ComputerName}[$fakeBoundParameter.ComputerName -eq $null] 69 | $tooltip = $_.name + " on " + $cname + "." 70 | 71 | createCompletionResult $_.name $_.name $tooltip 72 | } 73 | } 74 | 75 | $channelCompletion_Process = { 76 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 77 | 78 | $parms = @{} 79 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 80 | if ($fakeBoundParameter.VirtualHost) { $parms.Add("VirtualHost", $fakeBoundParameter.VirtualHost) } 81 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 82 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 83 | 84 | Get-RabbitMQChannel @parms | where name -like "$wordToComplete*" | select name | ForEach-Object { 85 | $cname = @{$true="localhost"; $false = $fakeBoundParameter.ComputerName}[$fakeBoundParameter.ComputerName -eq $null] 86 | $tooltip = $_.name + " on " + $cname + "." 87 | 88 | createCompletionResult $_.name $_.name $tooltip 89 | } 90 | } 91 | 92 | $queueCompletion_Process = { 93 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 94 | 95 | $parms = @{} 96 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 97 | if ($fakeBoundParameter.VirtualHost) { $parms.Add("VirtualHost", $fakeBoundParameter.VirtualHost) } 98 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 99 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 100 | 101 | Get-RabbitMQQueue @parms | where name -like "$wordToComplete*" | ForEach-Object { 102 | $cname = @{$true="localhost"; $false = $fakeBoundParameter.ComputerName}[$fakeBoundParameter.ComputerName -eq $null] 103 | $n = "$($_.name) ($($_.messages))" 104 | $tooltip = "$($_.name) on $cname/$($_.vhost) ($($_.messages) messages)." 105 | 106 | createCompletionResult $n $_.name $tooltip 107 | } 108 | } 109 | 110 | $routingKeyGeneration_Process = { 111 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 112 | 113 | $parms = @{} 114 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 115 | if ($fakeBoundParameter.VirtualHost) { $parms.Add("VirtualHost", $fakeBoundParameter.VirtualHost) } 116 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 117 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 118 | 119 | $tooltip = "Bind exchange " + $fakeBoundParameter.ExchangeName + " to queue " + $fakeBoundParameter.Name + "." 120 | 121 | createCompletionResult $fakeBoundParameter.Name $tooltip 122 | createCompletionResult $($fakeBoundParameter.ExchangeName + "-" + $fakeBoundParameter.Name) $tooltip 123 | createCompletionResult $($fakeBoundParameter.ExchangeName + "->" + $fakeBoundParameter.Name) $tooltip 124 | createCompletionResult $($fakeBoundParameter.ExchangeName + ".." + $fakeBoundParameter.Name) $tooltip 125 | } 126 | 127 | $routingKeyCompletion_Process = { 128 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 129 | 130 | $parms = @{} 131 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 132 | if ($fakeBoundParameter.VirtualHost) { $parms.Add("VirtualHost", $fakeBoundParameter.VirtualHost) } 133 | #if ($fakeBoundParameter.ExchangeName) { $parms.Add("ExchangeName", $fakeBoundParameter.ExchangeName) } 134 | if ($fakeBoundParameter.Name) { $parms.Add("Name", $fakeBoundParameter.Name) } 135 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 136 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 137 | 138 | #Get-RabbitMQQueueBinding @parms | where name -like "$wordToComplete*" | select routing_key | ForEach-Object { 139 | $a = Get-RabbitMQQueueBinding @parms 140 | $b = $a | where source -eq $fakeBoundParameter.ExchangeName | select routing_key 141 | 142 | $b | ForEach-Object { 143 | createCompletionResult $_.routing_key $_.routing_key $_.routing_key 144 | } 145 | } 146 | 147 | $userCompletion_Process = { 148 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) 149 | 150 | $parms = @{} 151 | if ($fakeBoundParameter.ComputerName) { $parms.Add("ComputerName", $fakeBoundParameter.ComputerName) } 152 | 153 | if ($fakeBoundParameter.Credentials) { $parms.Add("Credentials", $fakeBoundParameter.Credentials) } 154 | if ($fakeBoundParameter.UserName) { $parms.Add("UserName", $fakeBoundParameter.UserName) } 155 | if ($fakeBoundParameter.Password) { $parms.Add("Password", $fakeBoundParameter.Password) } 156 | 157 | Get-RabbitMQUser @parms | where name -like "$wordToComplete*" | ForEach-Object { 158 | $tooltip = "$($_.name) [$($_.tags)]" 159 | 160 | createCompletionResult $_.name $_.name $tooltip 161 | } 162 | } 163 | 164 | function createCompletionResult([string]$text, [string]$value, [string]$tooltip) { 165 | 166 | if ([string]::IsNullOrEmpty($value)) { return } 167 | if ([string]::IsNullOrEmpty($text)) { $text = $value } 168 | if ([string]::IsNullOrEmpty($tooltip)) { $tooltip = $value } 169 | 170 | $completionText = @{$true="'$value'"; $false=$value }[$value -match "\W"] 171 | $completionText = $completionText -replace '\[', '``[' -replace '\]', '``]' 172 | 173 | return New-Object System.Management.Automation.CompletionResult $completionText, $text, 'ParameterValue', $tooltip 174 | } 175 | 176 | if (-not $global:options) { $global:options = @{CustomArgumentCompleters = @{};NativeArgumentCompleters = @{}}} 177 | 178 | $global:options['CustomArgumentCompleters']['Test1:Name'] = $testCompletion_Process 179 | 180 | 181 | $global:options['CustomArgumentCompleters']['Get-RabbitMQOverview:Name'] = $computerNameCompletion_Process 182 | 183 | $global:options['CustomArgumentCompleters']['Get-RabbitMQVirtualHost:Name'] = $virtualHostCompletion_Process 184 | $global:options['CustomArgumentCompleters']['Get-RabbitMQVirtualHost:ComputerName'] = $computerNameCompletion_Process 185 | $global:options['CustomArgumentCompleters']['Add-RabbitMQVirtualHost:ComputerName'] = $computerNameCompletion_Process 186 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQVirtualHost:Name'] = $virtualHostCompletion_Process 187 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQVirtualHost:ComputerName'] = $computerNameCompletion_Process 188 | 189 | $global:options['CustomArgumentCompleters']['Get-RabbitMQExchange:Name'] = $exchangeCompletion_Process 190 | $global:options['CustomArgumentCompleters']['Get-RabbitMQExchange:VirtualHost'] = $virtualHostCompletion_Process 191 | $global:options['CustomArgumentCompleters']['Get-RabbitMQExchange:ComputerName'] = $computerNameCompletion_Process 192 | $global:options['CustomArgumentCompleters']['Add-RabbitMQExchange:VirtualHost'] = $virtualHostCompletion_Process 193 | $global:options['CustomArgumentCompleters']['Add-RabbitMQExchange:ComputerName'] = $computerNameCompletion_Process 194 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQExchange:Name'] = $exchangeCompletion_Process 195 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQExchange:VirtualHost'] = $virtualHostCompletion_Process 196 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQExchange:ComputerName'] = $computerNameCompletion_Process 197 | 198 | $global:options['CustomArgumentCompleters']['Get-RabbitMQConnection:Name'] = $connectionCompletion_Process 199 | $global:options['CustomArgumentCompleters']['Get-RabbitMQConnection:ComputerName'] = $computerNameCompletion_Process 200 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQConnection:Name'] = $connectionCompletion_Process 201 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQConnection:ComputerName'] = $computerNameCompletion_Process 202 | 203 | $global:options['CustomArgumentCompleters']['Get-RabbitMQNode:Name'] = $nodeCompletion_Process 204 | $global:options['CustomArgumentCompleters']['Get-RabbitMQNode:ComputerName'] = $computerNameCompletion_Process 205 | 206 | $global:options['CustomArgumentCompleters']['Get-RabbitMQChannel:Name'] = $channelCompletion_Process 207 | $global:options['CustomArgumentCompleters']['Get-RabbitMQChannel:VirtualHost'] = $virtualHostCompletion_Process 208 | $global:options['CustomArgumentCompleters']['Get-RabbitMQChannel:ComputerName'] = $computerNameCompletion_Process 209 | 210 | $global:options['CustomArgumentCompleters']['Get-RabbitMQQueue:Name'] = $queueCompletion_Process 211 | $global:options['CustomArgumentCompleters']['Get-RabbitMQQueue:VirtualHost'] = $virtualHostCompletion_Process 212 | $global:options['CustomArgumentCompleters']['Get-RabbitMQQueue:ComputerName'] = $computerNameCompletion_Process 213 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueue:VirtualHost'] = $virtualHostCompletion_Process 214 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueue:ComputerName'] = $computerNameCompletion_Process 215 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueue:Name'] = $queueCompletion_Process 216 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueue:VirtualHost'] = $virtualHostCompletion_Process 217 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueue:ComputerName'] = $computerNameCompletion_Process 218 | 219 | $global:options['CustomArgumentCompleters']['Get-RabbitMQQueueBinding:Name'] = $queueCompletion_Process 220 | $global:options['CustomArgumentCompleters']['Get-RabbitMQQueueBinding:VirtualHost'] = $virtualHostCompletion_Process 221 | $global:options['CustomArgumentCompleters']['Get-RabbitMQQueueBinding:ComputerName'] = $computerNameCompletion_Process 222 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueueBinding:Name'] = $queueCompletion_Process 223 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueueBinding:VirtualHost'] = $virtualHostCompletion_Process 224 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueueBinding:ComputerName'] = $computerNameCompletion_Process 225 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueueBinding:ExchangeName'] = $exchangeCompletion_Process 226 | $global:options['CustomArgumentCompleters']['Add-RabbitMQQueueBinding:RoutingKey'] = $routingKeyGeneration_Process 227 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueueBinding:Name'] = $queueCompletion_Process 228 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueueBinding:VirtualHost'] = $virtualHostCompletion_Process 229 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueueBinding:ComputerName'] = $computerNameCompletion_Process 230 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueueBinding:ExchangeName'] = $exchangeCompletion_Process 231 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQQueueBinding:RoutingKey'] = $routingKeyCompletion_Process 232 | 233 | $global:options['CustomArgumentCompleters']['Get-RabbitMQMessage:Name'] = $queueCompletion_Process 234 | $global:options['CustomArgumentCompleters']['Get-RabbitMQMessage:VirtualHost'] = $virtualHostCompletion_Process 235 | $global:options['CustomArgumentCompleters']['Get-RabbitMQMessage:ComputerName'] = $computerNameCompletion_Process 236 | 237 | $global:options['CustomArgumentCompleters']['Clear-RabbitMQQueue:Name'] = $queueCompletion_Process 238 | $global:options['CustomArgumentCompleters']['Clear-RabbitMQQueue:VirtualHost'] = $virtualHostCompletion_Process 239 | $global:options['CustomArgumentCompleters']['Clear-RabbitMQQueue:ComputerName'] = $computerNameCompletion_Process 240 | 241 | $global:options['CustomArgumentCompleters']['Copy-RabbitMQMessage:SourceQueueName'] = $queueCompletion_Process 242 | $global:options['CustomArgumentCompleters']['Copy-RabbitMQMessage:DestinationQueueName'] = $queueCompletion_Process 243 | $global:options['CustomArgumentCompleters']['Copy-RabbitMQMessage:VirtualHost'] = $virtualHostCompletion_Process 244 | $global:options['CustomArgumentCompleters']['Copy-RabbitMQMessage:ComputerName'] = $computerNameCompletion_Process 245 | 246 | $global:options['CustomArgumentCompleters']['Move-RabbitMQMessage:SourceQueueName'] = $queueCompletion_Process 247 | $global:options['CustomArgumentCompleters']['Move-RabbitMQMessage:DestinationQueueName'] = $queueCompletion_Process 248 | $global:options['CustomArgumentCompleters']['Move-RabbitMQMessage:VirtualHost'] = $virtualHostCompletion_Process 249 | $global:options['CustomArgumentCompleters']['Move-RabbitMQMessage:ComputerName'] = $computerNameCompletion_Process 250 | 251 | $global:options['CustomArgumentCompleters']['Get-RabbitMQUser:ComputerName'] = $computerNameCompletion_Process 252 | $global:options['CustomArgumentCompleters']['Get-RabbitMQUser:Name'] = $userCompletion_Process 253 | $global:options['CustomArgumentCompleters']['Add-RabbitMQUser:ComputerName'] = $computerNameCompletion_Process 254 | $global:options['CustomArgumentCompleters']['Add-RabbitMQUser:Name'] = $userCompletion_Process 255 | $global:options['CustomArgumentCompleters']['Set-RabbitMQUser:ComputerName'] = $computerNameCompletion_Process 256 | $global:options['CustomArgumentCompleters']['Set-RabbitMQUser:Name'] = $userCompletion_Process 257 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQUser:ComputerName'] = $computerNameCompletion_Process 258 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQUser:Name'] = $userCompletion_Process 259 | 260 | $global:options['CustomArgumentCompleters']['Get-RabbitMQPermission:ComputerName'] = $computerNameCompletion_Process 261 | $global:options['CustomArgumentCompleters']['Get-RabbitMQPermission:VirtualHost'] = $virtualHostCompletion_Process 262 | $global:options['CustomArgumentCompleters']['Get-RabbitMQPermission:User'] = $userCompletion_Process 263 | $global:options['CustomArgumentCompleters']['Add-RabbitMQPermission:ComputerName'] = $computerNameCompletion_Process 264 | $global:options['CustomArgumentCompleters']['Add-RabbitMQPermission:VirtualHost'] = $virtualHostCompletion_Process 265 | $global:options['CustomArgumentCompleters']['Add-RabbitMQPermission:User'] = $userCompletion_Process 266 | $global:options['CustomArgumentCompleters']['Set-RabbitMQPermission:ComputerName'] = $computerNameCompletion_Process 267 | $global:options['CustomArgumentCompleters']['Set-RabbitMQPermission:VirtualHost'] = $virtualHostCompletion_Process 268 | $global:options['CustomArgumentCompleters']['Set-RabbitMQPermission:User'] = $userCompletion_Process 269 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQPermission:ComputerName'] = $computerNameCompletion_Process 270 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQPermission:VirtualHost'] = $virtualHostCompletion_Process 271 | $global:options['CustomArgumentCompleters']['Remove-RabbitMQPermission:User'] = $userCompletion_Process 272 | 273 | $global:options['CustomArgumentCompleters']['Unregister-RabbitMQServer:ComputerName'] = $computerNameCompletion_Process 274 | 275 | $function:tabexpansion2 = $function:tabexpansion2 -replace 'End\r\n{','End { if ($null -ne $options) { $options += $global:options} else {$options = $global:options}' 276 | -------------------------------------------------------------------------------- /Tests/AddExchange.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\AddExchange.ps1" 4 | 5 | function TearDownTest() { 6 | 7 | $exchanges = Get-RabbitMQExchange -ComputerName $server e1, e2 8 | 9 | ($exchanges) | Remove-RabbitMQExchange -ComputerName $server -ErrorAction Continue -Confirm:$false 10 | } 11 | 12 | Describe -Tags "Example" "Add-RabbitMQExchange" { 13 | It "should create new Exchange" { 14 | 15 | Add-RabbitMQExchange -ComputerName $server -Type direct e1 16 | 17 | $actual = Get-RabbitMQExchange -ComputerName $server e1 | select -ExpandProperty name 18 | 19 | $actual | Should Be "e1" 20 | 21 | TearDownTest 22 | } 23 | 24 | It "should do nothing when Exchange already exists" { 25 | 26 | Add-RabbitMQExchange -ComputerName $server -Type direct "e1" 27 | Add-RabbitMQExchange -ComputerName $server -Type direct "e1" 28 | 29 | $actual = Get-RabbitMQExchange -ComputerName $server "e1" | select -ExpandProperty name 30 | 31 | $actual | Should Be "e1" 32 | 33 | TearDownTest 34 | } 35 | 36 | It "should create many Exchanges" { 37 | 38 | Add-RabbitMQExchange -ComputerName $server -Type direct e1,e2 39 | 40 | $actual = Get-RabbitMQExchange -ComputerName $server e1,e2 | select -ExpandProperty name 41 | 42 | $expected = $("e1", "e2") 43 | 44 | AssertAreEqual $actual $expected 45 | 46 | TearDownTest 47 | } 48 | 49 | It "should get Exchange to be created from the pipe" { 50 | 51 | $("e1", "e2") | Add-RabbitMQExchange -ComputerName $server -Type direct 52 | 53 | $actual = $($("e1", "e2") | Get-RabbitMQExchange -ComputerName $server) | select -ExpandProperty name 54 | 55 | $expected = $("e1", "e2") 56 | 57 | AssertAreEqual $actual $expected 58 | 59 | TearDownTest 60 | } 61 | 62 | It "should get Exchange with properties to be created from the pipe" { 63 | 64 | $pipe = $( 65 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "Name" = "e1"; "Type" = "direct" } 66 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "Name" = "e2"; "Type" = "fanout" } 67 | ) 68 | 69 | $pipe | Add-RabbitMQExchange 70 | 71 | $actual = $($pipe | Get-RabbitMQExchange -ComputerName $server) | select -ExpandProperty name 72 | 73 | $expected = $("e1", "e2") 74 | 75 | AssertAreEqual $actual $expected 76 | 77 | TearDownTest 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Tests/AddQueue.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\AddQueue.ps1" 4 | 5 | function TearDownTest() { 6 | 7 | $queues = Get-RabbitMQQueue -ComputerName $server -VirtualHost test 8 | 9 | ($queues) | Remove-RabbitMQQueue -ComputerName $server -VirtualHost test -ErrorAction Continue -Confirm:$false 10 | } 11 | 12 | Describe -Tags "Example" "Add-RabbitMQQueue" { 13 | 14 | It "should create new Queue" { 15 | 16 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1 17 | 18 | $actual = Get-RabbitMQQueue -ComputerName $server -VirtualHost test q1 | select -ExpandProperty name 19 | 20 | $actual | Should Be "q1" 21 | 22 | TearDownTest 23 | } 24 | 25 | It "should create Durable new Queue" { 26 | 27 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1 -Durable 28 | 29 | $actual = Get-RabbitMQQueue -ComputerName $server -VirtualHost test q1 | select -ExpandProperty durable 30 | 31 | $actual | Should Be $true 32 | 33 | TearDownTest 34 | } 35 | 36 | It "should create AutoDelete new Queue" { 37 | 38 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1 -AutoDelete 39 | 40 | $actual = Get-RabbitMQQueue -ComputerName $server -VirtualHost test q1 | select -ExpandProperty auto_delete 41 | 42 | $actual | Should Be $true 43 | 44 | TearDownTest 45 | } 46 | 47 | It "should create Durable, AutoDelete new Queue" { 48 | 49 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1 -Durable -AutoDelete 50 | 51 | $actual = Get-RabbitMQQueue -ComputerName $server -VirtualHost test q1 | select -ExpandProperty durable 52 | $actual | Should Be $true 53 | 54 | $actual = Get-RabbitMQQueue -ComputerName $server -VirtualHost test q1 | select -ExpandProperty auto_delete 55 | $actual | Should Be $true 56 | 57 | TearDownTest 58 | } 59 | 60 | It "should do nothing when Queue already exists" { 61 | 62 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1 63 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1 64 | 65 | $actual = Get-RabbitMQQueue -ComputerName $server -VirtualHost test q1 | select -ExpandProperty name 66 | $actual | Should Be "q1" 67 | 68 | TearDownTest 69 | } 70 | 71 | It "should create many Queues" { 72 | 73 | Add-RabbitMQQueue -ComputerName $server -VirtualHost test q1,q2,q3 74 | 75 | $actual = Get-RabbitMQQueue -ComputerName $server "q*" | select -ExpandProperty name 76 | 77 | $expected = $("q1", "q2", "q3") 78 | AssertAreEqual $actual $expected 79 | 80 | TearDownTest 81 | } 82 | 83 | It "should get queue names from the pipe" { 84 | 85 | $pipe = $("q1", "q1") 86 | 87 | $pipe| Add-RabbitMQQueue -ComputerName $server -VirtualHost test 88 | 89 | $actual = $($pipe | Get-RabbitMQQueue -ComputerName $server -VirtualHost test) | select -ExpandProperty name 90 | 91 | $expected = $pipe 92 | 93 | AssertAreEqual $actual $expected 94 | 95 | TearDownTest 96 | } 97 | 98 | It "should get queue definitions from the pipe" { 99 | 100 | $pipe = $( 101 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "VirtualHost" = "test"; "Name" = "q1" } 102 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "VirtualHost" = "test"; "Name" = "q2"; "Durable" = $true } 103 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "VirtualHost" = "test"; "Name" = "q3"; "AutoDelete" = $true } 104 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "VirtualHost" = "test"; "Name" = "q4"; "Durable" = $true; "AutoDelete" = $true } 105 | ) 106 | 107 | $pipe | Add-RabbitMQQueue 108 | 109 | $actual = $pipe | Get-RabbitMQQueue -ComputerName $server 110 | 111 | foreach ($e in $pipe) 112 | { 113 | $a = $actual | ? name -eq $e.Name 114 | 115 | $a | Should Not Be $null 116 | $a.vhost | Should Be $e.VirtualHost 117 | if ($e.Durable) { $a.durable | Should Be $true } 118 | if ($e.AutoDelete) { $a.auto_delete | Should Be $true } 119 | } 120 | 121 | TearDownTest 122 | } 123 | 124 | } -------------------------------------------------------------------------------- /Tests/AddVirtualHost.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\AddVirtualHost.ps1" 4 | 5 | function TearDownTest() { 6 | 7 | $vhosts = Get-RabbitMQVirtualHost -ComputerName $server vh3, vh4 8 | 9 | ($vhosts) | Remove-RabbitMQVirtualHost -ComputerName $server -ErrorAction Continue -Confirm:$false 10 | } 11 | 12 | Describe -Tags "Example" "Add-RabbitMQVirtualHost" { 13 | It "should create new Virtual Host" { 14 | 15 | Add-RabbitMQVirtualHost -ComputerName $server "vh3" 16 | 17 | $actual = Get-RabbitMQVirtualHost -ComputerName $server "vh3" | select -ExpandProperty name 18 | 19 | $actual | Should Be "vh3" 20 | 21 | TearDownTest 22 | } 23 | 24 | It "should do nothing when VirtualHost already exists" { 25 | 26 | Add-RabbitMQVirtualHost -ComputerName $server "vh3" 27 | Add-RabbitMQVirtualHost -ComputerName $server "vh3" 28 | 29 | $actual = Get-RabbitMQVirtualHost -ComputerName $server "vh3" | select -ExpandProperty name 30 | 31 | $actual | Should Be "vh3" 32 | 33 | TearDownTest 34 | } 35 | 36 | It "should create many Virtual Hosts" { 37 | 38 | Add-RabbitMQVirtualHost -ComputerName $server "vh3", "vh4" 39 | 40 | $actual = Get-RabbitMQVirtualHost -ComputerName $server "vh3", "vh4" | select -ExpandProperty name 41 | 42 | $expected = $("vh3", "vh4") 43 | 44 | AssertAreEqual $actual $expected 45 | 46 | TearDownTest 47 | } 48 | 49 | It "should get VirtualHost to be created from the pipe" { 50 | 51 | $("vh3", "vh4") | Add-RabbitMQVirtualHost -ComputerName $server 52 | 53 | $actual = $($("vh3", "vh4") | Get-RabbitMQVirtualHost -ComputerName $server) | select -ExpandProperty name 54 | 55 | $expected = $("vh3", "vh4") 56 | 57 | AssertAreEqual $actual $expected 58 | 59 | TearDownTest 60 | } 61 | 62 | It "should get VirtualHost with ComputerName to be created from the pipe" { 63 | 64 | $pipe = $( 65 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "Name" = "vh3" } 66 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "Name" = "vh4" } 67 | ) 68 | 69 | $pipe | Add-RabbitMQVirtualHost 70 | 71 | $actual = $($pipe | Get-RabbitMQVirtualHost -ComputerName $server) | select -ExpandProperty name 72 | 73 | $expected = $("vh3", "vh4") 74 | 75 | AssertAreEqual $actual $expected 76 | 77 | TearDownTest 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /Tests/GetExchange.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\GetExchange.ps1" 4 | 5 | 6 | Describe -Tags "Example" "Get-RabbitMQExchange" { 7 | 8 | It "should get Exchanges registered with the server" { 9 | 10 | $actual = Get-RabbitMQExchange -ComputerName $server | select -ExpandProperty name 11 | 12 | $actual.length | Should Not Be 0 13 | } 14 | 15 | It "should get Exchanges filtered by name" { 16 | 17 | $actual = Get-RabbitMQExchange -ComputerName $server "amq.*" | select -ExpandProperty name | Sort-Object | Get-Unique 18 | 19 | $expected = $( 20 | "amq.direct", 21 | "amq.fanout", 22 | "amq.headers", 23 | "amq.match", 24 | "amq.rabbitmq.log", 25 | "amq.rabbitmq.trace", 26 | "amq.topic" 27 | ) 28 | 29 | AssertAreEqual $actual $expected 30 | } 31 | 32 | It "should get Exchanges filtered by VirtualHost" { 33 | 34 | $actual = Get-RabbitMQExchange -ComputerName $server -VirtualHost / 35 | 36 | $actual.length | Should Not Be 0 37 | } 38 | 39 | It "should get Exchange names to filter by from the pipe" { 40 | 41 | $actual = $('amq.direct', 'amq.fanout') | Get-RabbitMQExchange -ComputerName $server | select -ExpandProperty name | Sort-Object | Get-Unique 42 | 43 | $expected = $('amq.direct', 'amq.fanout') 44 | 45 | AssertAreEqual $actual $expected 46 | } 47 | 48 | It "should get VirtualHost and ComputerName from the pipe" { 49 | 50 | $pipe = $( 51 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "VirtualHost" = "/"; "Name"="amq.direct" } 52 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "VirtualHost" = "/"; "Name"="amq.fanout" } 53 | ) 54 | 55 | $actual = $pipe | Get-RabbitMQExchange | select -ExpandProperty name 56 | 57 | $expected = $('amq.direct', 'amq.fanout') 58 | 59 | AssertAreEqual $actual $expected 60 | } 61 | 62 | #It "should pipe result from itself" { 63 | # 64 | # $actual = Get-RabbitMQExchange -ComputerName $server | Get-RabbitMQExchange | select -ExpandProperty name 65 | # 66 | # $expected = Get-RabbitMQExchange -ComputerName $server | select -ExpandProperty name 67 | # 68 | # AssertAreEqual $actual $expected 69 | #} 70 | } 71 | 72 | -------------------------------------------------------------------------------- /Tests/GetOverview.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\GetOverview.ps1" 4 | 5 | Describe -Tags "Example" "Get-RabbitMQOverview" { 6 | 7 | It "should get server overview" { 8 | 9 | $actual = Get-RabbitMQOverview -ComputerName $server | select -ExpandProperty ComputerName 10 | 11 | $actual | Should Be $server 12 | } 13 | 14 | It "should get overview for several servers" { 15 | 16 | $actual = Get-RabbitMQOverview -ComputerName $server, $server | select -ExpandProperty ComputerName 17 | 18 | $actual | Should Be $server 19 | } 20 | 21 | It "should get server names from pipe" { 22 | 23 | $actual = $($($server) | Get-RabbitMQOverview) | select -ExpandProperty ComputerName 24 | 25 | $actual | Should Be $server 26 | } 27 | } -------------------------------------------------------------------------------- /Tests/GetVirtualHost.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\GetVirtualHost.ps1" 4 | 5 | Describe -Tags "Example" "Get-RabbitMQVirtualHost" { 6 | 7 | It "should get Virtual Hosts registered with the server" { 8 | 9 | $actual = Get-RabbitMQVirtualHost -ComputerName $server | select -ExpandProperty name 10 | 11 | $expected = $("/", "vh1", "vh2") 12 | 13 | AssertAreEqual $actual $expected 14 | } 15 | 16 | It "should get Virtual Hosts filtered by name" { 17 | 18 | $actual = Get-RabbitMQVirtualHost -ComputerName $server vh* | select -ExpandProperty name 19 | 20 | $expected = $("vh1", "vh2") 21 | 22 | AssertAreEqual $actual $expected 23 | } 24 | 25 | It "should get VirtualHost names to filter by from the pipe" { 26 | 27 | $actual = $('vh1', 'vh2') | Get-RabbitMQVirtualHost -ComputerName $server | select -ExpandProperty name 28 | 29 | $expected = $("vh1", "vh2") 30 | 31 | AssertAreEqual $actual $expected 32 | } 33 | 34 | It "should get VirtualHost and ComputerName from the pipe" { 35 | 36 | $pipe = $( 37 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "Name" = "vh1" } 38 | New-Object -TypeName psobject -Prop @{"ComputerName" = $server; "Name" = "vh2" } 39 | ) 40 | 41 | $actual = $pipe | Get-RabbitMQVirtualHost | select -ExpandProperty name 42 | 43 | $expected = $("vh1", "vh2") 44 | 45 | AssertAreEqual $actual $expected 46 | } 47 | 48 | It "should pipe result from itself" { 49 | 50 | $actual = Get-RabbitMQVirtualHost -ComputerName $server | Get-RabbitMQVirtualHost | select -ExpandProperty name 51 | 52 | $expected = Get-RabbitMQVirtualHost -ComputerName $server | select -ExpandProperty name 53 | 54 | AssertAreEqual $actual $expected 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Tests/RemoveExchange.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\RemoveExchange.ps1" 4 | 5 | Describe -Tags "Example" "Remove-RabbitMQExchange" { 6 | It "should remove existing Exchange" { 7 | 8 | Add-RabbitMQExchange -ComputerName $server "e1" -Type direct 9 | Remove-RabbitMQExchange -ComputerName $server "e1" -Confirm:$false 10 | 11 | $actual = Get-RabbitMQExchange -ComputerName $server e1 | select -ExpandProperty name 12 | 13 | $actual | Should Be $() 14 | } 15 | } -------------------------------------------------------------------------------- /Tests/RemoveVirtualHost.Tests.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | . "$here\TestSetup.ps1" 3 | . "$here\..\RemoveVirtualHost.ps1" 4 | 5 | Describe -Tags "Example" "Remove-RabbitMQVirtualHost" { 6 | It "should remove existing Virtual Host" { 7 | 8 | Add-RabbitMQVirtualHost -ComputerName $server "vh3" 9 | Remove-RabbitMQVirtualHost -ComputerName $server "vh3" -Confirm:$false 10 | 11 | $actual = Get-RabbitMQVirtualHost -ComputerName $server "vh*" | select -ExpandProperty name 12 | 13 | $actual | Should Be $("vh1", "vh2") 14 | } 15 | } -------------------------------------------------------------------------------- /Tests/TestSetup.ps1: -------------------------------------------------------------------------------- 1 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path 2 | #$server = "192.168.232.129" 3 | $server = "localhost" 4 | 5 | . "$here\..\GetRabbitMQCredentials.ps1" 6 | . "$here\..\Constants.ps1" 7 | . "$here\..\Invoke_RestMethodProxy.ps1" 8 | . "$here\..\NamesToString.ps1" 9 | . "$here\..\PreventUnEscapeDotsAndSlashesOnUri.ps1" 10 | . "$here\..\SendItemsToOutput.ps1" 11 | 12 | 13 | function AssertAreEqual($actual, $expected) { 14 | 15 | if ($actual -is [System.Array]) { 16 | if ($expected -isnot [System.Array]) { throw "Expected {$expected} to be an array, but it is not." } 17 | 18 | if ($actual.Length -ne $expected.Length) 19 | { 20 | $al = $actual.Length 21 | $el = $expected.Length 22 | throw "Expected $al elements but were $el" 23 | } 24 | 25 | for ($i = 0; $i -lt $actual.Length; $i++) 26 | { 27 | $a = $actual[$i] 28 | $e = $expected[$i] 29 | if ($a -ne $e) 30 | { 31 | throw "Expected element at position $i to be {$e} but was {$a}" 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /UnregisterServer.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Unregisters RabbitMQ server. 4 | 5 | .DESCRIPTION 6 | Unregister-RabbitMQ server cmdlet allows to remove RabbitMQ server from tab completition list for ComputerName. 7 | 8 | .EXAMPLE 9 | Unregister-RabbitMQServer '127.0.0.1' 10 | 11 | Removes server 127.0.0.1 from auto completition list for ComputerName parameter. 12 | #> 13 | function Unregister-RabbitMQServer 14 | { 15 | [CmdletBinding()] 16 | Param 17 | ( 18 | # Name of the RabbitMQ server to be unregistered. 19 | [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] 20 | $ComputerName 21 | ) 22 | 23 | Begin 24 | { 25 | if (-not $global:RabbitMQServers) 26 | { 27 | $global:RabbitMQServers = @() 28 | } 29 | } 30 | Process 31 | { 32 | $obj += $global:RabbitMQServers | ? ListItemText -eq $ComputerName 33 | 34 | if ($obj) 35 | { 36 | $global:RabbitMQServers = $global:RabbitMQServers | ? ListItemText -ne $ComputerName 37 | } 38 | } 39 | End 40 | { 41 | } 42 | } -------------------------------------------------------------------------------- /en-US/about_RabbitMQTools.help.txt: -------------------------------------------------------------------------------- 1 | .Synopsis 2 | Describes how to user RabbitMQTools for managing and administering RabbitMQ servers. 3 | 4 | .DESCRIPTION 5 | The RabbitMQ Tools is an open source module containing cmdlets for managing and administering RabbitMQ servers. 6 | 7 | Most of the cmdlets are using RabbitMQ Managing API to access and manipulate the server. -------------------------------------------------------------------------------- /en-US/about_UnEsapingDotsAndSlashes.help.txt: -------------------------------------------------------------------------------- 1 | Explains what the UnEscapeDotsAndSlashed flag is and how it is used by RabbitMQTools. 2 | 3 | DESCRIPTION 4 | 5 | Depending on the .NET Framework version you are using, the system will treat URLs which contain encoded forward slash (%2f) differently. In the .NET Framework versions earlier than 4.5 the URL which contains encoded forward slash is automatically un-escaped which changes it from something like http://localhost:15672/#/queues/%2f to http://localhost:15672/#/queues//. Unfortunately, servers will treat those two URLs as different. Especially RabbitMQ management API doesn't recognises the latter, un-escaped form and throws an exception. 6 | 7 | To enable support for all operations in RabbitMQ management API, the RabbitMQTools module is disabling flag called UnEscapeDotsAndSlashes in the underlying UriParser class. This allows for invoking calls to URLs containing encoded forward slash in them. Because the operation is modifying some internal state of .NET Framework objects, there is a potential risk that the behaviour related to URI management in the whole PowerShell session will be affected. 8 | 9 | To minimise that risk, the RabbitMQTools module is creating a proxy over Invoke-RestMethod cmdlet which adds new switch called -AllowEscapedDotsAndSlashes. When set, and the requested URL contains encoded forward slash then before the call to the service is made, the UnEscapeDotsAndSlashes flags is disabled. After receiving response from the service, the flag is set back, so all consecutive calls will behave as expected (unless they have -AllowEscapedDotsAndSlashes set as well). 10 | 11 | 12 | WHY THIS IS HAPPENNING 13 | 14 | I found a weak explanation that this behaviour was done by design to decrease potential malicious attack. As the web has changed, the problem become less dangerous, but for compatibility reasons it was still in .NET Framework until version 4.5. You can read a bit more on the topic at: https://connect.microsoft.com/VisualStudio/feedback/details/511010/erroneous-uri-parsing-for-encoded-reserved-characters-according-to-rfc-3986 15 | 16 | 17 | I'M WORKING WITH SERVICE WHICH REQUIRES UNESCAPED FORWARD SLASH, CAN I REUSE YOUR CODE? 18 | 19 | If you require that your URI class doesn't automatically un-escape dots and slashed that I am encouraging you to have a look at the way it is implemented in RabbitMQTools. You can find the source code on GitHub at: https://github.com/mariuszwojcik/RabbitMQTools. The files which will be of special interest to you are: 20 | 21 | - Invoke_RestMethodProxy.ps1 22 | - PreventUnEscapeDotsAndSlashesOnUri.ps1 23 | 24 | There also is a blog post explaining hot to implement the hack. You can find it at: http://mariuszwojcik.wordpress.com/2014/03/04/how-to-prevent-invoke-restmethod-from-un-escaping-forward-slashes/ 25 | 26 | HOW TO TEST IF MY SYSTEM IS AFFECTED 27 | 28 | If you are using .NET Framework version earlier than 4.5 than your system is affected. Versions 4.5 and older do not automatically un-escape dots and slashes in URLs. 29 | You can find a good example of how to test your system in the article at: http://mariuszwojcik.wordpress.com/2014/03/04/how-to-prevent-invoke-restmethod-from-un-escaping-forward-slashes/ 30 | 31 | 32 | LINKS: 33 | 34 | http://mariuszwojcik.wordpress.com/2014/03/04/how-to-prevent-invoke-restmethod-from-un-escaping-forward-slashes/ 35 | 36 | Blog article on how to prevent un-escaping dots and slashes in PowerShell. 37 | 38 | 39 | https://github.com/mariuszwojcik/RabbitMQTools 40 | 41 | Source code of the RabbitMQTools module. 42 | 43 | 44 | https://connect.microsoft.com/VisualStudio/feedback/details/511010/erroneous-uri-parsing-for-encoded-reserved-characters-according-to-rfc-3986 45 | 46 | A bit of explanation from Microsoft on why the un-escaping is happening. --------------------------------------------------------------------------------