How to Connect to Office 365 (Exchange Online) via PowerShell
If you’re an Office 365 administrator, connecting to Exchange Online using PowerShell can give you powerful control over your environment. Whether you’re managing mailboxes, running reports, or configuring settings not available in the admin portal, PowerShell is a go-to tool for advanced tasks. It allows for automation of repetitive tasks, saving valuable time and reducing the chance of human error. With just a few commands, you can streamline administrative duties across your entire organization. PowerShell also enables bulk actions, advanced filtering, and integration with scripts, making it an essential tool for IT professionals managing modern Microsoft 365 environments efficiently, securely, and with greater scalability and consistency across multiple tenants.
Follow the steps below to establish a secure remote PowerShell session with Exchange Online:
-
Open PowerShell as an Administrator
Right-click on the Start button, select “Windows PowerShell (Admin)” or “Terminal (Admin)” depending on your system. -
Allow Script Execution
Run the following command:Set-ExecutionPolicy RemoteSigned
If prompted, type Y and press Enter to confirm the change. -
Enter Your Office 365 Admin Credentials
Run this command to launch a login prompt:$UserCredential = Get-Credential
Enter your Office 365 administrator email (e.g.,[email protected]
) and password. -
Create a New PowerShell Session
Now, run the following command to start a new session with Exchange Online:- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUrl https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
- Import the Remote Session
Next, import the session into your local PowerShell environment:Import-PSSession $Session
You are now connected to Office 365 Exchange Online via PowerShell! You can begin running Exchange-related commands, such as managing mailboxes or distribution groups. When you’re finished, don’t forget to run Remove-PSSession $Session
to cleanly disconnect your session. This helps free up resources and ensures a secure closure of your remote connection. For ongoing management tasks, consider scripting common commands to save time and maintain consistency across your environment.

