Connect to Exchange Online via PowerShell

Modified on Mon, 1 Jul, 2019 at 11:50 AM

Note about MFA: If using MFA to authenticate your Admin user(s), you'll need to download a special PowerShell app (Basic Auth not supported) - see MS Article here


The full Microsoft article is here: http://technet.microsoft.com/en-us/library/jj984289(v=exchg.150).aspx but you may find our solution easier to follow. Read on...


Run PowerShell as an Administrator on your local computer, then type these commands:

 

set-executionpolicy unrestricted


(Agree to the policy change)


$UserCredential = Get-Credential

 

(Enter the credentials of a user with Administrator rights to Exchange Online)


 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

  

Import-PSSession $Session

 

(Wait whilst the remote commands are imported)


You should now be able to use PowerShell to communicate directly to the Exchange Online server as if it were attached to your local network!


Now you can test communication using a simple command such as this:

Get-Mailbox

 

A full list of commands are available here: http://technet.microsoft.com/en-us/library/jj200780(v=exchg.150).aspx



Useful commands:

 

Create a rule to send auto-replies from a shared mailbox:

Set-MailboxAutoReplyConfiguration -Identity sharedmailbox@domain.com -AutoReplyState Enabled -InternalMessage "Internal auto-reply message." -ExternalMessage "External auto-reply message."

### Set IMAP ###
Get-CasMailbox email@address.com
Set-CasMailbox email@address.com -ImapEnabled $true

 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article