Created
August 1, 2020 09:45
-
-
Save michevnew/029ee0bec0baaefcbf5556b32e108542 to your computer and use it in GitHub Desktop.
This file contains 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
$tenantID = "tenant.onmicrosoft.com" #your tenantID or tenant root domain | |
$appID = "12345678-1234-1234-1234-1234567890AB" #the GUID of your app | |
$client_secret = "XXXXXXXXXXXXXXXXXXXXXX" #client secret for the app | |
$body = @{ | |
client_id = $AppId | |
scope = "https://outlook.office365.com/.default" | |
client_secret = $client_secret | |
grant_type = "client_credentials" | |
} | |
$authenticationResult = Invoke-WebRequest -Method Post -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -ContentType "application/x-www-form-urlencoded" -Body $body -ErrorAction Stop | |
$token = ($authenticationResult.Content | ConvertFrom-Json).access_token | |
$Authorization = "Bearer {0}" -f $Token | |
$Password = ConvertTo-SecureString -AsPlainText $Authorization -Force | |
$Ctoken = New-Object System.Management.Automation.PSCredential -ArgumentList "OAuthUser@XXXXXXXXXXXXXXXXXX",$Password #replace your tenantGUID here | |
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/PowerShell-LiveId?BasicAuthToOAuthConversion=true&email=user@tenant.onmicrosoft.com" -Credential $Ctoken -Authentication Basic -AllowRedirection -Verbose | |
Import-PSSession $Session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment