-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas_bulk_disenrol_students_from_course.ps1
36 lines (26 loc) · 1.35 KB
/
canvas_bulk_disenrol_students_from_course.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
$token = "<TOKEN>"
$headers = @{"Authorization"="Bearer "+$token}
$courseIds = 3433 # Can contain multiple ids: 3269, 3273, 3277, 3271, 3275
############################################################################################################################
foreach($courseId in $courseIds) {
$response = Invoke-RestMethod `
-URI "https://<HOSTNAME>:443/api/v1/courses/$($courseId)/enrollments?type[]=StudentEnrollment" `
-Headers $headers `
-Method GET `
-FollowRelLink
# Because of pagination, $RESPONSE will often contain a multidimensional array, with one
# element for each page. Each page in turn contains multiple objects, which are the results of the query.
# This is a shortcut to get an array of all enrollment IDs in the multidimensional array.
$enrollmentIds = $response.id
# Should equal the number of students enrolled in the course.
Write-host "Got $($enrollmentIds.length) student enrollments for course ID $courseId."
foreach($enrollmentId in $enrollmentIds) {
$uri = "https://<HOSTNAME>:443/api/v1/courses/$($courseId)/enrollments/$($enrollmentId)?task=delete"
Write-Host $uri
$response = Invoke-RestMethod `
-URI $URI `
-Headers $headers `
-Method DELETE
$response
}
}