-
Notifications
You must be signed in to change notification settings - Fork 26
/
New-ZoomMeetingPoll.ps1
112 lines (91 loc) · 3.04 KB
/
New-ZoomMeetingPoll.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
<#
.SYNOPSIS
Creates a new Zoom meeting poll.
.DESCRIPTION
Creates a new Zoom meeting poll. Meeting must be a scheduled meeting.
Instant meetings do not have polling features enabled.
.PARAMETER MeetingId
The meeting ID.
.PARAMETER Title
Poll title.
.PARAMETER Questions
Array of questions. Requrires three values:
[string]name - Question name
[string]type - Question type
single - Single choice
multiple - Multiple choice
Example:
$Questions = @(
@('Favorite number?', 'multiple', @('1', '2', '3')), @('Favorite letter?', 'multiple', @('a', 'b', 'c'))
)
Can also pass New-ZoomMeetingPollQuestion as an array. Example:
$Questions = @(
(New-ZoomMeetingPollQuestion -Name 'Favorite Number?' -type 'multiple' -answers '1,2,3'),
(New-ZoomMeetingPollQuestion -Name 'Favorite letter??' -type 'multiple' -answers 'a,b,c))
)
.PARAMETER ApiKey
The Api Key.
.PARAMETER ApiSecret
The Api Secret.
.EXAMPLE
$Questions = @(
@('Favorite number?', 'multiple', @('1', '2', '3')), @('Favorite letter?', 'multiple', @('a', 'b', 'c'))
)
New-ZoomMeetingPoll 123456789 -Title 'Favorite numbers and letters' -Questions $Questions
#>
function New-ZoomMeetingPoll {
[CmdletBinding()]
param (
[Parameter(
Mandatory = $True,
ValueFromPipeline = $True,
ValueFromPipelineByPropertyName = $True,
Position = 0
)]
[Alias('meeting_id')]
[string]$MeetingId,
[Parameter(ValueFromPipelineByPropertyName = $True)]
[string]$Title,
[Parameter(ValueFromPipelineByPropertyName = $True)]
[string[]]$Questions,
[ValidateNotNullOrEmpty()]
[string]$ApiKey,
[ValidateNotNullOrEmpty()]
[string]$ApiSecret
)
begin {
#Generate Headers and JWT (JSON Web Token)
$Headers = New-ZoomHeaders -ApiKey $ApiKey -ApiSecret $ApiSecret
}
process {
$Request = [System.UriBuilder]"https://api.zoom.us/v2/meetings/$MeetingId/polls"
$RequestBody = @{}
if ($PSBoundParameters.ContainsKey('Title')) {
$RequestBody.Add('title', $Title)
}
if ($PSBoundParameters.ContainsKey('Questions')) {
$RequestBody.Add('questions', $Questions)
}
$RequestBody = $RequestBody | ConvertTo-Json -Depth 10
$response = Invoke-ZoomRestMethod -Uri $request.Uri -Headers ([ref]$Headers) -Body $RequestBody -Method POST -ApiKey $ApiKey -ApiSecret $ApiSecret
Write-Output $response
}
}
function New-ZoomMeetingPollQuestion {
param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[string]$Name,
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateSet('single', 'multiple')]
[string]$Type,
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[Alias('answer')]
[string[]]$Answers
)
process {
$Question = @(
$Name, $Type, $Answers
)
return $Question
}
}