使用PowerShell发送DELETE API请求
我正在使用 PowerShell 读取数据库,获取用户 ID 列表,然后删除特定课程中的所有人。由于课程包含超过 1000 条记录,我已在请求语句中添加了分页 (per_page=100)。但是,我的删除语句一次仅删除 100 条记录。当我重新运行它时,它将删除接下来的 100 个,依此类推。我希望它立即删除所有人。我认为我需要在 API 请求上放置一个 Do While 循环,但不确定这是否是正确的方法。任何帮助将不胜感激。我已在此处包含代码。
$RequestURL = "$domainurl/$CourseID/enrollments?type[]=StudentEnrollment&state[]=active&per_page=100"
$Results = Invoke-WebRequest -Uri $RequestURL -Headers $headers -Method GET -UseBasicParsing
$json = $Results | ConvertFrom-Json # Convert the results from JSON
foreach($obj in $json) {
$ID = $obj.id # user id
$URL = '$domainurl' + $CourseID + '/enrollments/' + $ID + '?task=delete'
Invoke-WebRequest -Uri $Url -Headers $headers -Method Delete -UseBasicParsing | write-host
}
谢谢。
I am using PowerShell to read a database, get a list of user IDs and then delete everyone from a particular course. Because the course contains over 1000 records I have added pagination (per_page=100) to my request statement. However, my delete statement only removes 100 records at a time. When I re-run it, it will remove the next 100 and so on. I want it to remove everyone at once. I think that I need to place a Do While loop on my API requests but am not sure if that is the proper way to do it. Any assistance would be greatly appreciated. I have included the code here.
$RequestURL = "$domainurl/$CourseID/enrollments?type[]=StudentEnrollment&state[]=active&per_page=100"
$Results = Invoke-WebRequest -Uri $RequestURL -Headers $headers -Method GET -UseBasicParsing
$json = $Results | ConvertFrom-Json # Convert the results from JSON
foreach($obj in $json) {
$ID = $obj.id # user id
$URL = '$domainurl' + $CourseID + '/enrollments/' + $ID + '?task=delete'
Invoke-WebRequest -Uri $Url -Headers $headers -Method Delete -UseBasicParsing | write-host
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论