Advertisement
Guest User

Untitled

a guest
May 4th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. # Adding the AD library to your PowerShell Session.
  2. Add-Type -Path 'C:Program FilesMicrosoft Azure Active Directory ConnectMicrosoft.IdentityModel.Clients.ActiveDirectory.dll'
  3.  
  4. # This is the tenant id of you Azure AD. You can use tenant name instead if you want.
  5. $tenantID = "<the tenant id of Azure AD>"
  6. $authString = "https://login.microsoftonline.com/$tenantID"
  7.  
  8. # Here, the username must be MFA disabled, and must not be a live id.
  9. $username = "<the username of the AD's owner>"
  10. $password = "<the password of the above user>"
  11.  
  12. # The resource URI for your token.
  13. $resource = "https://graph.windows.net/"
  14.  
  15. # This is the common client id.
  16. $client_id = "1950a258-227b-4e31-a9cf-717495945fc2"
  17.  
  18. # Create a client credential with the above common client id, username and password.
  19. $creds = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" `
  20. -ArgumentList $username,$password
  21.  
  22. # Create a authentication context with the above authentication string.
  23. $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" `
  24. -ArgumentList $authString
  25.  
  26. # Acquire access token from server.
  27. $authenticationResult = $authContext.AcquireToken($resource,$client_id,$creds)
  28.  
  29. # Use the access token to setup headers for your http request.
  30. $authHeader = $authenticationResult.AccessTokenType + " " + $authenticationResult.AccessToken
  31. $headers = @{"Authorization"=$authHeader; "Content-Type"="application/json"}
  32.  
  33. # Get the users.
  34. Invoke-RestMethod -Method GET -Uri "https://graph.windows.net/$tenantID/users?api-version=1.6-internal"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement