-
Notifications
You must be signed in to change notification settings - Fork 61
/
GetUser.ps1
96 lines (72 loc) · 2.89 KB
/
GetUser.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<#
.Synopsis
Gets list of users.
.DESCRIPTION
The Get-RabbitMQUser gets list of users registered in RabbitMQ server.
The result may be zero, one or many RabbitMQ.User objects.
To get users from remote server you need to provide -ComputerName.
The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html
.EXAMPLE
Get-RabbitMQUser
Gets list of all users in local RabbitMQ server.
.EXAMPLE
Get-RabbitMQUser -ComputerName myrabbitmq.servers.com
Gets list of all users in myrabbitmq.servers.com server.
.EXAMPLE
Get-RabbitMQUser gu*
Gets list of all users whose name starts with "gu".
.EXAMPLE
Get-RabbitMQUser guest, admin
Gets data for users guest and admin.
.EXAMPLE
Get-RabbitMQUser -View Flat
Gets flat list of all users. This view doesn't group users by ComputerName as the default view do.
.INPUTS
You can pipe Names and ComputerNames to filter results.
.OUTPUTS
By default, the cmdlet returns list of RabbitMQ.User objects which describe user.
.LINK
https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin.
#>
function Get-RabbitMQUser
{
[CmdletBinding(DefaultParameterSetName='defaultLogin', SupportsShouldProcess=$true, PositionalBinding=$false)]
Param
(
# Name of the computer hosting RabbitMQ server. Defalut value is localhost.
[parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)]
[string[]]$Name,
# Name of the computer hosting RabbitMQ server. Defalut value is localhost.
[parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[Alias("cn", "HostName")]
[string]$ComputerName = $defaultComputerName,
[ValidateSet("Default", "Flat")]
[string]$View,
# UserName to use when logging to RabbitMq server. Default value is guest.
[Parameter(Mandatory=$true, ParameterSetName='login')]
[string]$UserName,
# Password to use when logging to RabbitMq server. Default value is guest.
[Parameter(Mandatory=$true, ParameterSetName='login')]
[string]$Password,
[Parameter(Mandatory=$true, ParameterSetName='cred')]
[PSCredential]$Credentials
)
Begin
{
$Credentials = NormaliseCredentials
}
Process
{
if ($pscmdlet.ShouldProcess("server $ComputerName", "Get user(s)"))
{
$result = GetItemsFromRabbitMQApi -ComputerName $ComputerName $Credentials "users"
$result = ApplyFilter $result 'name' $Name
$result | Add-Member -NotePropertyName "ComputerName" -NotePropertyValue $ComputerName
if (-not $View) { SendItemsToOutput $result "RabbitMQ.User" }
else { SendItemsToOutput $result "RabbitMQ.User" | ft -View $View }
}
}
End
{
}
}