Skip to content

Instantly share code, notes, and snippets.

@tdewin
Created September 12, 2017 17:35
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 tdewin/00c01252dfdb2884831c1a30c733c81a to your computer and use it in GitHub Desktop.
Save tdewin/00c01252dfdb2884831c1a30c733c81a to your computer and use it in GitHub Desktop.
VBO365 Rest API testing with powershell
#ignore self signed
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$auth = Invoke-RestMethod -Method post "https://localhost:4443/v1/token" -Body @{
"grant_type"="password";
"username"="administrator";
"password"="<Don't know your pass>"
}
write-host ("Got auth token {0}" -f $auth.access_token)
#send this headers to pass your token and the send and accept json
$reqheaders = @{
"Authorization"=("Bearer {0}" -f $auth.access_token);
'Accept'='application/json';
'Content-Type'='application/json'
}
$orgname = "exchange.x.local"
$orgs = Invoke-RestMethod -Method get -uri "https://localhost:4443/v1/Organizations" -Headers $reqheaders | ? { $_.name -match $orgname }
$orgs
$orgs._links.jobs.href
if ($orgs.count -gt 0) {
$jobs = Invoke-RestMethod -Method get -uri $orgs._links.jobs.href -Headers $reqheaders
$jobs | select name,id,isEnabled
$oujob = $jobs | ? { $_.name -eq "OU=Belgium,DC=x,DC=local" }
$mailboxes = Invoke-RestMethod -Method get -uri $oujob._links.selectedMailboxes.href -Headers $reqheaders
$mailboxes
$mailboxes.results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment