The correct way to connect to Office 365 using PowerShell

Every time I’m sitting at a new computer and try to connect to Office 365 using PowerShell I normally have forgotten how.

I google for it and often the top result is either old information or just doesn’t work.

Some instructions ask you to install things like the Azure online services and Microsoft Online Services Sign in assistant.. some of which say you need higher versions of one installed and you try to install the newer version of the other it tells you a newer version is already installed.

I’ve found the best place to start is this set of documentation but also make sure you have run this command first:
Set-ExecutionPolicy RemoteSigned
(Note that you need to run powershell as an administrator to set this!)

Single Factor Authentication Admins:

New URL: https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps

Old URL: https://msdn.microsoft.com/en-us/library/cc952755(v=exchsrvcs.149).aspx

Old Old URL (now dead link): http://help.outlook.com/en-gb/140/cc952755.aspx

The ExecutionPolicy commands followed by the connection commands from the above address worked fine on a stock Windows 8.1 computer without installing any extra programs!

connecttopowerhsell

Multiple factor authenctication enabled admin accounts:

Install Exchange Online Management: https://docs.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps#install-and-maintain-the-exo-v2-module

Install-Module -Name ExchangeOnlineManagement

See: https://docs.microsoft.com/en-us/powershell/exchange/connect-to-exchange-online-powershell?view=exchange-ps#connect-to-exchange-online-powershell-using-mfa

Then

Import-Module ExchangeOnlineManagement</p>
Connect-ExchangeOnline -ShowProgress $true -UserPrincipalName youradmin@emailaddress

Disconnect with

Disconnect-ExchangeOnline

This entry was posted in Uncategorized. Bookmark the permalink.

Comment on this topic

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s