How to Connect to Your Office 365 Tenant via PowerShell (Updated 2025)
PowerShell is one of the most powerful tools for managing Microsoft 365. It gives you access to features and settings that can be hard to find-or completely missing—in the admin portal. No more slow navigation, browser logins, or multi-page clicks; just direct control.
Before you can connect, you need to understand Execution Policies, which control script execution:
AllSigned – Only scripts signed by a trusted publisher run.
Bypass – Nothing is blocked; no warnings.
Default – Restricted on Windows clients; RemoteSigned on Windows servers.
RemoteSigned – Local scripts run; scripts from the internet must be signed.
Restricted – No scripts run.
Undefined – No policy set; defaults to Restricted unless set via Group Policy.
Unrestricted – Runs all scripts; prompts before running unsigned scripts from the internet.
For most scenarios, RemoteSigned is recommended. Bypass is useful if you trust the source and want to avoid prompts, but remember-less security means more risk.
Modern Method (Supports MFA – Recommended)
Run PowerShell as Administrator
Set execution policy (press A to accept):
Set-ExecutionPolicy RemoteSignedConnect to Exchange Online:
Connect-ExchangeOnline -UserPrincipalName [email protected]You are now connected to your tenant’s Exchange environment.
When done, disconnect:
Disconnect-ExchangeOnline
Old Method (Does Not Support MFA – Legacy Only)
Run PowerShell as Administrator
Set execution policy:
Set-ExecutionPolicy RemoteSignedEnter credentials:
$UserCredential = Get-CredentialCreate a session:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirectionImport the session:
Import-PSSession $Session -DisableNameCheckingWhen finished, disconnect:
Remove-PSSession $Session
Notes for 2025:
The modern Connect-ExchangeOnline cmdlet (part of the Exchange Online PowerShell V3 module) is the preferred method-faster, more secure, and supports MFA.
The old Basic Auth method is deprecated and disabled in most tenants unless explicitly re-enabled for specific scenarios.
You can also connect to other services (SharePoint, Teams, etc.), but for stability, it’s often easier to connect to one service at a time.