invoke-restmethod multipart content

Copper Contributor

I have a PowerShell script that calls the Canvas VLE SIS import API to batch enrol students into a course.  The script calls invoke-restmethod to post a multipart CSV file with the details of the students to enrol.  This is the format of the file:

 

 

 

 

--CanvasData
Content-Disposition: form-data; name="attachment"; filename="enrol_S2020-A52172-D0016-1.csv"
Content-Type: text/csv; charset=utf-8

"section_id","user_id","role","status"
"S2020-A52172-D0016","000000","student","active"
"S2020-A52172-D0016","111111","student","active"
"S2020-A52172-D0016","222222","student","active"
"S2020-A52172-D0016","333333","student","active"
"S2020-A52172-D0016","444444","student","active"
--CanvasData--

 

 

 

 

The content is uploaded and processed successfully when running on PowerShell 4.0.  However, if I run the same script in PowerShell 5.1, the content is uploaded but the processing fails.  I have verified that the CSV content is valid, so the only reason for this failure that I can think of is that PowerShell 5.1 handles multipart content different to 4.0.

 

Any suggestions on how I can change the script / multipart content so that the enrolment upload works on PowerShell 5.1 ?

0 Replies