Skip to content

Instantly share code, notes, and snippets.

@jforet1
jforet1 / script.ps1
Created September 16, 2020 14:18
Exchange Online PowerShell - MFA Timeout Fix
$username = "replaceme@contoso.com"
Connect-ExchangeOnline -UserPrincipalName $username
$mailboxes = Get-Mailbox -ResultSize:unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'"
$mailboxes | ForEach-Object {
$connectionstatus = Get-PSSession | Where-Object {$_.ConfigurationName -like "Microsoft.Exchange"}
if ($connectionstatus.State -ne "Opened") {
Connect-ExchangeOnline -UserPrincipalName $username
}