Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Adding the AD library to your PowerShell Session.
- Add-Type -Path 'C:Program FilesMicrosoft Azure Active Directory ConnectMicrosoft.IdentityModel.Clients.ActiveDirectory.dll'
- # This is the tenant id of you Azure AD. You can use tenant name instead if you want.
- $tenantID = "<the tenant id of Azure AD>"
- $authString = "https://login.microsoftonline.com/$tenantID"
- # Here, the username must be MFA disabled, and must not be a live id.
- $username = "<the username of the AD's owner>"
- $password = "<the password of the above user>"
- # The resource URI for your token.
- $resource = "https://graph.windows.net/"
- # This is the common client id.
- $client_id = "1950a258-227b-4e31-a9cf-717495945fc2"
- # Create a client credential with the above common client id, username and password.
- $creds = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" `
- -ArgumentList $username,$password
- # Create a authentication context with the above authentication string.
- $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" `
- -ArgumentList $authString
- # Acquire access token from server.
- $authenticationResult = $authContext.AcquireToken($resource,$client_id,$creds)
- # Use the access token to setup headers for your http request.
- $authHeader = $authenticationResult.AccessTokenType + " " + $authenticationResult.AccessToken
- $headers = @{"Authorization"=$authHeader; "Content-Type"="application/json"}
- # Get the users.
- 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