This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-GitLabUser.ps1
107 lines (92 loc) · 2.65 KB
/
Get-GitLabUser.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
97
98
99
100
101
102
103
104
105
106
107
function Get-GitLabUser
{
<#
.SYNOPSIS
Gets Gitlab User
.DESCRIPTION
The Get-GitlabUser function retruns a list of users
By default this function returns all available users
you can filter these users on 'blocked' or 'active'
returns single user if id is passed
Admins can retreive a lot mor info conserning users then non-admins:
they can serach on 'username' and filter on 'external'
.EXAMPLE
Get-GitLabUser
---------------------------------------------------------------
Returns all users including blockedUsers
.EXAMPLE
Get-GitLabUser -ID 20
---------------------------------------------------------------
Returns the user with ID 20
.EXAMPLE
Get-GitLabUser -Blocked
---------------------------------------------------------------
Returns all users that are blocked
#>
[CmdletBinding(DefaultparametersetName = 'AllUsers')]
[Alias()]
[OutputType()]
param(
#filter Users on state: Active
[Parameter(ParameterSetName = 'AllUsersActive')]
[Switch]$Active,
#Filter users on state: Blocked
[Parameter(ParameterSetName = 'AllUsersBlocked')]
[Switch]$Blocked,
#Retrun only external Users
[Parameter(ParameterSetNAme = 'AllUsersActive')]
[Parameter(ParameterSetName = 'AllUsersBlocked')]
[bool]$External,
#Get single user by ID
[Parameter(ParameterSetName = 'SingleUserByID',
Mandatory = $true)]
[Alias('ID')]
[int]$UserID,
#get single user by UserName
[Parameter(ParameterSetNAme = 'SingleUserByUserName',
Mandatory = $true)]
[string]$UserName,
# Existing GitlabConnector Object, can be retrieved with Get-GitlabConnect
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitLabConnect)
)
$httpmethod = 'get'
$apiurl = 'users'
$parameters = @{}
if($PSCmdlet.ParameterSetName -like 'AllProjects*')
{
if($Active)
{
$parameters.'active' = 'true'
}
if ($Blocked)
{
$parameters.'blocked' = 'true'
}
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'External')
{
if($External)
{
$parameters.'external' = 'true'
}
else
{
$parameters.'external' = 'false'
}
}
}
if($PSCmdlet.ParameterSetName -eq 'SingleUserByID')
{
$apiurl += ('/{0}' -f $UserID)
}
if($PSCmdlet.ParameterSetName -eq 'SingleUserByUserName')
{
if($UserName)
{
$parameters.'username' = $UserName
}
}
$GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
}