-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerShell-BlackBoardConnect.psm1
164 lines (137 loc) · 5.09 KB
/
PowerShell-BlackBoardConnect.psm1
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
Function Render-MultiPartFormFields
{
Param(
$FieldsHash,
$Boundary
)
$ReturnString = "";
ForEach ($Field in $FieldsHash.GetEnumerator())
{
if ($Field.Key -eq "fFile")
{
$ReturnString += $Boundary + "`r`n"
$ReturnString += "Content-Disposition: form-data; name=""fFile""; filename=""upload.txt""`r`n"
$ReturnString += "Content-Type: text/plain`r`n`r`n"
$ReturnString += Get-Content $($Field.Value) -Raw
$ReturnString += "`r`n"
}
else {
$ReturnString += $Boundary + "`r`n"
$ReturnString += "Content-Disposition: form-data; name=""$($Field.Key)""`r`n`r`n"
$ReturnString += "$($Field.Value)`r`n"
}
}
$ReturnString +="$Boundary--`r`n"
$ReturnString
}
Function Upload-Contacts
{
<#
.PARAMETER UserName
UserName for the BlackBoard Connect Upload Service
.PARAMETER Password
Password for the BlackBoard Connect Upload Service
.PARAMETER ContactType
The ContactType to assign to contacts in this upload.
.PARAMETER RefreshType
All contacts of the selected tpye wil be removed and replaced by Contact Type data in your import file.
Selecting anything other than "None" presents a risk of data loss.
Selecting "None" will only affect the contacts contained in your file.
.PARAMETER PreserveData
Will only update the fields provided in the upload.
Fields with blank data for a contact will be cleared.
ReferenceCode is required when this is selected.
#>
Param(
[String]
$UserName,
[String]
$Password,
[ValidateSet("All","Student","Admin","Faculty","Staff","Other")]
[String]
$ContactType,
[ValidateSet("All","Student","Admin","Faculty","Staff","Other","None")]
[String]
$RefreshType="None",
[bool]
$PreserveData = $true ,
[String]
$UploadFilePath
)
$Boundary = "-----------------------------AaB03x"
$UploadFields = @{}
$UploadFields['fNTIUser'] = $UserName
$UploadFields['fNTIPassEnc'] = $Password
$UploadFields['fContactType'] = $ContactType
if ( $RefreshType -ne "None" )
{
$UploadFields['fRefreshType'] = $RefreshType
}
$UploadFields['fPreserveData'] = [int]$PreserveData
$UploadFields['fFile'] = $UploadFilePath
$UploadFields['fSubmit'] = 1
$PostBody = $(Render-MultiPartFormFields -FieldsHash $UploadFields -Boundary $Boundary)
$Response = Invoke-WebRequest -Uri "https://www.blackboardconnected.com/contacts/importer_portal.asp?qDest=imp" -Method POST -Body $PostBody -ContentType "multipart/form-data; boundary=$Boundary" -UserAgent "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
$Response
}
Function New-AttendanceCall
{
<#
.PARAMETER UserName
UserName for the BlackBoard Connect Upload Service
.PARAMETER Password
Password for the BlackBoard Connect Upload Service
.PARAMETER ContactType
The ContactType to assign to contacts in this upload.
.PARAMETER TemplateName
Name of the BlackBoard Connect Attendance Template to use
.PARAMETER CallTime
This is the time the call will be scheduled on the website.
Defaults to 7:30:00 PM
It should be formatted by XX:XX:XX AM.
Set blank if you would like to schedule immediately
.PARAMETER TimeZone
Your TimeZone
Defaults to ET
.PARAMETER AttCode
List of Attendance Codes
.PARAMETER AttendanceFile
File containing Attendance Call Data
#>
Param(
[String]
$UserName,
[String]
$Password,
[ValidateSet("All","Student","Admin","Faculty","Staff","Other")]
[String]
$ContactType,
[String]
$TemplateName,
[String]
$CallTime = "07:30:00 PM",
[String]
[ValidateSet("HA","AK","PT","MT","CT","ET","AT")]
$TimeZone = "ET",
[String]
$AttCode,
[String]
$AttendanceFile
)
if (-Not $(Test-Path $AttendanceFile))
{
Throw "Attendance File required."
}
$Boundary = "-------------------------AaB03x"
$UploadFields = @{}
$UploadFields['fNTIUser'] = $UserName
$UploadFields['fNTIPass'] = $Password
$UploadFields['fContactType'] = $ContactType
$UploadFields['fMessageTitle'] = $TemplateName
$UploadFields['fNTITime'] = $CallTime
$UploadFields['fNTITimeZone'] = $TimeZone
$UploadFields['fFile'] = $AttendanceFile
$PostBody = $(Render-MultiPartFormFields -FieldsHash $UploadFields -Boundary $Boundary)
$Response = Invoke-WebRequest -Uri "https://upload.blackboardconnect.com/AutoNotification/SendNotification" -Method POST -Body $PostBody -ContentType "multipart/form-data; boundary=$Boundary" -UserAgent "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)"
$Response
}