Created
July 5, 2020 10:21
-
-
Save gscales/1b7973f6fe194804270c9934a887b705 to your computer and use it in GitHub Desktop.
MFA Exchange Online Powershell
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
Import-Module CredentialManager | |
Import-Module ./AzureMFAOTPv2.ps1 | |
$Cred = Get-Credential | |
$token = Get-AccessTokenMFA -OTP (Get-TimeBasedOneTimePassword -SharedSecret (Get-StoredCredential -Target Auth.GS -AsCredentialObject).Password) -Credential $Cred -ClientId 'a0c73c16-a7e3-4564-9a95-2bdf47383716' -Scopes 'https://outlook.office365.com/.default' | |
$domain = $Cred.UserName.Split('@')[1] | |
$tokenValue = ConvertTo-SecureString "Bearer $($token.access_token)" -AsPlainText -Force | |
$credential = New-Object System.Management.Automation.PSCredential($Cred.UserName, $tokenValue) | |
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid?DelegatedOrg=$($domain)&BasicAuthToOAuthConversion=true" -Credential $credential -Authentication Basic -AllowRedirection | |
Import-PSSession $session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment