-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathAdd-MSTTeamUser.ps1
93 lines (79 loc) · 2.61 KB
/
Add-MSTTeamUser.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
#Requires -Version 5.0
#Requires -Modules microsoftteams
<#
.SYNOPSIS
Adds an owner or member to the team
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
Requires Module microsoftteams
Requires a ScriptRunner Microsoft 365 target
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/Members
.Parameter GroupId
[sr-en] GroupId of the team
[sr-de] Gruppen ID des Teams
.Parameter User
[sr-en] User's UPN (user principal name)
[sr-de] UPN
.Parameter Users
[sr-en] One or more User UPN's (user principal name)
[sr-de] Ein oder mehrere UPNs
.Parameter Role
[sr-en] User role
[sr-de] Rolle der Benutzer
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory = $true, ParameterSetName = "Single")]
[Parameter(Mandatory = $true, ParameterSetName = "Multi")]
[string]$GroupId,
[Parameter(Mandatory = $true, ParameterSetName = "Single")]
[string]$User,
[Parameter(Mandatory = $true, ParameterSetName = "Multi")]
[string[]]$Users,
[Parameter(ParameterSetName = "Single")]
[Parameter(ParameterSetName = "Multi")]
[ValidateSet('Member','Owner')]
[string]$Role
)
Import-Module microsoftteams
try{
$team = Get-Team -GroupId $GroupId -ErrorAction Stop | Select-Object -ExpandProperty DisplayName
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'GroupId' = $GroupId
}
if([System.String]::IsNullOrWhiteSpace($Role) -eq $false){
$cmdArgs.Add('Role',$Role)
}
if($PSCmdlet.ParameterSetName -eq 'Single'){
$Users = @($User)
}
$result = @()
foreach($usr in $Users){
try{
$null = Add-TeamUser @cmdArgs -User $usr
$result += "User $($usr) added to team $($team)"
}
catch{
$result += "Error. Add user $($usr) to team $($team)"
}
}
if($SRXEnv) {
$SRXEnv.ResultMessage = $result
}
else{
Write-Output $result
}
}
catch{
throw
}
finally{
}