-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathMSTLibrary.ps1
343 lines (283 loc) · 11.4 KB
/
MSTLibrary.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#Requires -Version 5.0
#Requires -Modules microsoftteams
function ConnectMSTeams(){
<#
.SYNOPSIS
Open a connection to Microsoft Teams
.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
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/_LIB_
.Parameter MTCredential
Credential object containing the Microsoft Teams user/password
.Parameter TenantID
Specifies the ID of a tenant
.Parameter LogLevel
Specifies the log level
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory = $true)]
[PSCredential]$MTCredential,
[string]$TenantId,
[ValidateSet('Info','Error','Warning','None')]
[string]$LogLevel = 'Info'
)
try{
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'Confirm' = $false
'LogLevel' = $LogLevel
'Credential' = $MTCredential
}
if([System.String]::IsNullOrWhiteSpace($TenantId) -eq $false){
$cmdArgs.Add('TenantId', $TenantId)
}
$null = Connect-MicrosoftTeams @cmdArgs
}
catch{
throw
}
finally{
}
}
function DisconnectMSTeams(){
<#
.SYNOPSIS
Closes the connection to Microsoft Teams
.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
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/_LIB_
#>
[CmdLetBinding()]
Param(
)
try{
Disconnect-MicrosoftTeams -Confirm:$false
}
catch{
throw
}
finally{
}
}
function FillParameters(){
<#
.SYNOPSIS
Writes parameter values to parameter hashtable
.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
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/_LIB_
.Parameter BoundParameters
PSBoundParameters
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory = $true)]
$BoundParameters
)
try{
if($null -eq $BoundParameters){
return
}
foreach($key in $BoundParameters.Keys){
if($BoundParameters.Item($key).GetType().Name -eq 'Boolean'){
$Global:cmdArgs.Add($key,$BoundParameters.Item($key))
$Global:Properties += $key
}
}
}
catch{
throw
}
finally{
}
}
function CreateFacts(){
<#
.SYNOPSIS
Sends a message to a Team Channel
.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
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/_LIB_
.Parameter ActivityFacts
Array with hashtable Hashtable with an entry.
Each hashtable is one line
#>
param(
[hashtable[]]$ActivityFacts
)
[hashtable[]]$Facts = @()
foreach($item in $Activityfacts){
[hashtable]$out = @{'name' = ($item.Keys | Select-Object -First 1);'value'=($item.Values | Select-Object -First 1)}
$Facts += $out
}
return $Facts
}
function SendMessage2Channel{
<#
.SYNOPSIS
Sends a message to a Team Channel
.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
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/_LIB_
.Parameter WebhookURL
The URL of your Webhook, it must be match with "https://outlook.office.com/webhook/"
.Parameter Message
The body of the message to publish on Teams
.Parameter Title
The Title of the message to publish on Teams
.Parameter MessageColor
The color theme for the message
.Parameter ActivityTitle
The Activity title of the message to publish on Teams
.Parameter ActivitySubtitle
The Activity subtitle of the message to publish on Teams
.Parameter ActivityFacts
Array with hashtable Hashtable with an entry.
Each hashtable is one line
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory = $true)]
[ValidatePattern("^https://outlook.office.com/webhook/*")]
[string]$WebhookURL,
[Parameter(Mandatory = $true)]
[string]$Message,
[string]$Title,
[ValidateSet('Orange','Green','Red')]
[string]$MessageColor,
[string]$ActivityTitle,
[string]$ActivitySubtitle,
[hashtable[]]$ActivityFacts
)
try{
[hashtable]$cmdArgs = @{}
[hashtable]$section =@{}
if([System.String]::IsNullOrWhiteSpace($Title) -eq $false){
$cmdArgs.Add('Title',$Title)
}
if([System.String]::IsNullOrWhiteSpace($ActivityTitle) -eq $false){
$section.Add('activityTitle',$ActivityTitle)
}
if([System.String]::IsNullOrWhiteSpace($ActivitySubtitle) -eq $false){
$section.Add('activitySubtitle',$ActivitySubtitle)
}
$cmdArgs.Add('Text',$Message)
if(($null -ne $ActivityFacts) -and ($ActivityFacts.Count -gt 0)){
[hashtable[]]$sectionFacts = CreateFacts -ActivityFacts $ActivityFacts
$section.Add('facts',@($sectionFacts))
}
$cmdArgs.Add('sections',@($section))
switch ($MessageColor){
'Orange'{
$cmdArgs.Add('themeColor','FFC300')
}
'Green'{
$cmdArgs.Add('themeColor','008000')
}
'Red'{
$cmdArgs.Add('themeColor','FF0000')
}
}
# Build the request
$Params = @{
Headers = @{'accept'='application/json'}
Body = $cmdArgs | ConvertTo-Json -Depth 5
Method = 'Post'
URI = $WebhookURL
}
$null = Invoke-RestMethod @Params
}
catch{
throw
}
finally{
}
}
function ConnectS4B(){
<#
.SYNOPSIS
Open a Skype for Business online session
.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 v 1.1.6 or higher
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/O365/MS-Teams/_LIB_
.Parameter MSTCredential
Credential object containing the Skype for Business user/password
.Parameter OverrideAdminDomain
Specifies the domain of the tenant to be managed
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory = $true)]
[PSCredential]$MSTCredential,
[string]$OverrideAdminDomain
)
try{
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'Credential' = $MSTCredential
}
if($[System.String]::IsNullOrWhiteSpace($OverrideAdminDomain)-eq $false){
$cmdArgs.Add('OverrideAdminDomain',$OverrideAdminDomain)
}
$Global:session = New-CsOnlineSession @cmdArgs
Import-PSSession -Session $Global:session -ErrorAction Stop
}
catch{
throw
}
finally{
}
}