# 24.Oct.2018 09:50AM
# To Run => powershell -ExecutionPolicy Bypass -File "C:\BizTalk_Zone\PowerShellScripts\Learn_idnumber_update.ps1"
$theDomain = "https://learn.sm.ph"
$theToken = "0f90b7ad55ed7d123bcf173ded79b843"
# $theDomain = "https://sm-sandbox.ph"
# $theToken = "18c0b4b7as2caeaca23bfww9aoc7ee40"
$generic_headers = @{ Authorization = $generic_BasicAuthValue }
function getUrl()
{
return $theDomain + "/webservice/rest/server.php?wstoken=" + $theToken
}
function updateIdNumber($id, $idNumber)
{
$urlBase = getUrl
$uri = $urlBase + "&wsfunction=core_user_update_users&moodlewsrestformat=xml&users[0][id]=$id&users[0][idnumber]=$idNumber"
$uri
return Invoke-RestMethod -Method 'Post' -Uri $uri
}
function getDetails($key, $value)
{
$urlBase = getUrl
$uri = $urlBase + "&wsfunction=core_user_get_users&moodlewsrestformat=xml&criteria[0][key]=$key&criteria[0][value]=$value"
$uri
return Invoke-RestMethod -Method 'Get' -Uri $uri
}
$key = 'id'
$id = '3875'
$idnumber = '00000'
# $result = getDetails $key $id
$counter = 0
$idnumbers = Import-Csv -path "C:\BizTalk_Zone\PowerShellScripts\learn_idnumber.csv"
ForEach ($item in $idnumbers){
if ($counter -lt 2000){
$counter += 1
$id = $item.id
$idnumber = $item.idnumber
Write-Output "id: $id | idnumber: $idnumber | counter: $counter"
$result = updateIdNumber $id $idnumber
Write-Output "wait 3 seconds? ..."
Start-Sleep -Seconds 3
Write-Output $result
} else {
break
}
}
Comments
Post a Comment