알아낼 수없는 문제가 있습니다. 그것은 풀 수없는 구문 문제입니다.Powershell에서 함수 매개 변수에 여러 매개 변수 전달
function putStudentCourse ($userName, $courseId)
{
$url = "http://myurl/learn/api/public/v1/courses/courseId:" + $courseId + "https://stackoverflow.com/users/userName:" + $userName
$contentType = "application/json"
$basicAuth = post_token
$headers = @{
Authorization = $basicAuth
}
$body = @{
grant_type = 'client_credentials'
}
$data = @{
courseId = $courseId
availability = @{
available = 'Yes'
}
courseRoleId = 'Student'
}
$json = $data | ConvertTo-Json
$putStudent = Invoke-RestMethod -Method Put -Uri $url -ContentType $contentType -Headers $headers -Body $json
return $json
}
그리고 내 주요 방법 :
#MAIN
$userName = "user02";
$courseId = "CourseTest101"
$output = putStudentCourse($userName, $courseId)
Write-Output $output
이 지금 그냥 처음 베일 ($ 사용자 이름)를 반환하지만,이 같은 출력을 보여줍니다
의 난이 기능이 있다고 가정 해 봅시다{
"availability": {
"available": "Yes"
},
"courseRoleId": "Student",
"courseId": null
}
어쨌든 $ courseId는 채워지지 않으며 이유가 확실하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 도움이 될 것입니다.
추가 참고 사항 : [strict mode 사용] (https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/set-strictmode)을 사용하면이 잘못된 함수 호출 사용. – briantist