Created
March 1, 2018 20:43
-
-
Save rayterrill/ca4cb181a0e42ac84b01a84792a6f456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ClientID = "CLIENT_ID" # Should be a ~36 hex character string; insert your info here | |
| $ClientSecret = "CLIENT_PASSWORD" # Should be a ~44 character string; insert your info here | |
| $tenantdomain = "DOMAIN.onmicrosoft.com" # For example, contoso.onmicrosoft.com | |
| $loginURL = "https://login.microsoft.com" | |
| $resource = "https://graph.microsoft.com" | |
| $body = @{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret} | |
| $oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$tenantdomain/oauth2/token?api-version=1.0 -Body $body | |
| Write-Output $oauth | |
| if ($oauth.access_token -ne $null) { | |
| $headerParams = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"} | |
| $url = "https://graph.microsoft.com/beta/identityRiskEvents" | |
| Write-Output $url | |
| $myReport = (Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url) | |
| ($myReport.Content | ConvertFrom-JSON).value | Export-CSV output.csv | |
| foreach ($event in ($myReport.Content | ConvertFrom-Json).value) { | |
| Write-Output $event | |
| } | |
| } else { | |
| Write-Host "ERROR: No Access Token" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment