-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoodleAPI_createUSER.ps1
51 lines (31 loc) · 1.48 KB
/
moodleAPI_createUSER.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$lastname = "Testowy"
$firstname = "Test"
$usrname = "testowytest" # nazwa uzytkownika tylko male litery
$email = "[email protected]"
$phone = "123456789"
$password = "password"
$auth = "manual"
$functionname = "core_user_create_users"
$token = "toekn"
$url = "https://moodleaddress/webservice/rest/server.php?wsfunction=$functionname&wstoken=$token&users[0][username]=$usrname&users[0][password]=$password&users[0][firstname]=$firstname&users[0][lastname]=$lastname&users[0][email]=$email&users[0][phone1]=$phone"
<#
$body = @{
wsfunction = $functionname
wstoken = $token
}
#>
Invoke-RestMethod -Method 'Post' -Uri $url
#core_user_get_users
$functionname_get = "core_user_get_users"
$login = $usrname
$url = "https://moodleaddress/webservice/rest/server.php?wsfunction=$functionname_get&wstoken=$token&criteria[0][key]=username&criteria[0][value]=$login"
$response = Invoke-RestMethod -Method 'Post' -Uri $url | select OuterXml
[xml]$xml = $response.OuterXml
$id = $xml.RESPONSE.SINGLE.KEY[0].MULTIPLE.SINGLE.KEY[0].VALUE
#enrol_manual_enrol_users
$functionname_enrol = "enrol_manual_enrol_users"
$courseID = "7" # kurs akrualności
$roleID = "5" # rola student
$url = "https://moodleaddress/webservice/rest/server.php?wsfunction=$functionname_enrol&wstoken=$token&enrolments[0][roleid]=$roleID&enrolments[0][userid]=$id&enrolments[0][courseid]=$courseID"
Invoke-RestMethod -Method 'Post' -Uri $url