Skip to content

Instantly share code, notes, and snippets.

@michevnew
Created August 9, 2020 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michevnew/987a7e13655a5e71659de0ef1b994a67 to your computer and use it in GitHub Desktop.
Save michevnew/987a7e13655a5e71659de0ef1b994a67 to your computer and use it in GitHub Desktop.
HTTP error handler
$authHeader = @{
'Authorization'=$authenticationResult.Result.CreateAuthorizationHeader()
'Content-Type' = 'application\json'
}
$uri = "https://graph.microsoft.com/v1.0/users/user@tenant.onmicrosoft.com"
$body = @{mobilePhone="+421905111222"} | ConvertTo-Json
try {
Invoke-WebRequest -Method Patch -Uri $uri -Body $body -Verbose -Headers $authHeader -ContentType "application/json"
}
catch {
$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$errResp = $streamReader.ReadToEnd() | ConvertFrom-Json
$streamReader.Close()
$errResp.error.message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment