How to Fix PowerShell Hangs When Connecting to Exchange Online
Question details
The user needs a way to resolve an issue where PowerShell completely stops responding immediately after entering administrator credentials to connect to Exchange Online.

- Product
- Exchange Online
- Device & OS
- Windows / Azure Server
- Scenario
- Attempting to establish a remote PowerShell session to manage Exchange Online from a local computer or an Azure server.
- Observed behavior
- PowerShell hangs and fails to return a usable command prompt after credentials are submitted, often due to lingering or stalled sessions on the server side.
Verify that your internet connection is stable and ensure you are using the latest version of the ExchangeOnlineManagement module before attempting to reconnect.
Allow Stalled Server Sessions to Expire
The most common reason for this hang is an active but unresponsive session on the Exchange server. Letting the session naturally time out will clear the connection block.
Exchange Online limits the number of concurrent PowerShell sessions an admin can have open. If a previous script or connection was closed improperly, the server still registers it as active.
When you attempt to connect again, the server cannot allocate a new session, causing the local PowerShell window to freeze while waiting for a response.
Click the 'X' on your current frozen PowerShell window, or use Task Manager (Ctrl + Shift + Esc) to end the PowerShell background process.
Wait for the stalled sessions on the Exchange server to automatically expire. This typically takes 15 to 30 minutes, though in some severe cases, administrators report needing to wait a few hours or overnight.
Open a new PowerShell window by right-clicking the Start menu and selecting 'Windows PowerShell (Admin)'.
Run your standard 'Connect-ExchangeOnline' cmdlet and enter your credentials. The prompt should now return successfully.

Request Specialized Scripts to Force-Close Sessions
If you cannot wait for the timeout period, you will need advanced administrative commands to forcefully list and terminate the stalled sessions.
Simplify Your Workflow with WPS Office
Troubleshooting backend Microsoft Exchange Server problems and hung PowerShell modules can disrupt your entire workday. While IT resolves the server connectivity, keep your business moving with WPS Office. It provides a robust, lightweight, and completely free alternative to heavy Office installations.

Frequently Asked Questions
Why does PowerShell hang only when connecting to Exchange Online from my Azure server?
Azure servers frequently utilize shared IPs or specific network security group (NSG) rules. If a previous Exchange Online connection dropped silently due to a network timeout, the server-side session remains active. When you try to reconnect from the same environment, the module hangs waiting for the previous connection state to clear.
Can I prevent stalled sessions when using Exchange Online PowerShell?
Yes. The best way to prevent stalled sessions is to always gracefully close your connection when you finish your administrative tasks. Run the 'Disconnect-ExchangeOnline' cmdlet at the end of every script or manual session to explicitly tell the server to free up the connection.
How long does a stalled Exchange PowerShell session take to clear?
By default, idle Exchange Online PowerShell sessions are designed to time out after about 15 to 30 minutes on the server side. However, if the session is locked in a stalled state rather than simply idle, users sometimes have to wait several hours for the backend maintenance processes to drop the connection.
Does updating the ExchangeOnlineManagement module fix the freezing issue?
Updating to the latest version of the ExchangeOnlineManagement (EXO V3) module is highly recommended. Newer module versions handle REST API connections and modern authentication much better than older versions, reducing the chances of credentials causing a terminal hang.




