Share via


PowerShell Tip: Exchange Online Session

Often my exchange admins will say this

"I have trouble connecting to Exchange Online using Windows Azure Active Directory PowerShell Module to do my tasks."

Listening to this, I asked what is the error you get? They said many and it's difficult to explain. One major thing windows credential pops up every now and then. We checked network bandwidth and connectivity it all gave positive result. Do you know some reason?

Experiment:

help Get-PSSession -Detailed

Look at the state of the session :

001
002
003
004
005
006
007
008
PS>Get-PSSession | Format-List State,Idletimeout,Computername,Configurationname


State                  : Broken
IdleTimeout            : 900000
ComputerName           : outlook.office365.com
ConfigurationName      : Microsoft.Exchange

 

I do see the session reads as BROKEN
**
Solution:

**Please don't blame Exchange, PowerShell or Network. The default idle Timeout is 900000 seconds. So if you want to change it you have to specify that during initiation of the connection like below :

001
002
$SessionOption = New-PSSessionOption -IdleTimeout 43200000
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential (Get-Credential) -Authentication Basic -AllowRedirection -SessionOption $SessionOption

Now you can  Specify an IdleTimeout value between 60000 and 43200000 only. Try specifying it outside this range and you will be greeted with an error.

If Session State is OPENED you can continue your work with no chaos.

Get-PSSession | Select -Property *

Adding to the above the
Enjoy PowerShell :)