Save Connectivity to Office 365, Exchange Online, Azure AD in PowerShell Profile

Nothing extremely deep or new here, I just noticed there isn’t any posts out there that lay this out clear and direct for a new Office 365 implementation geared specifically towards Exchange Online and Azure AD. This is good for a new Office 365 customer or admin, after migration to get them set up using Remote PowerShell.

You can also add in other services such as SharePoint or Skype For Business and you can locate those here:

Now, onto the instructions.


Ensure you have the following installed;

Start by checking if you have a PowerShell profile enabled or not (Skip past this portion if you know that you do)
Open PowerShell as Administrator and type the following:
Test-path $profile
If the value is false, type the following:
New-item –type file –force $profile
Now, open your PowerShell profile:
Notepad $profile
Once the profile is open, paste in the following commands to Add-In connectivity to Office 365 PowerShell and Exchange Online PowerShell:
$credential = Get-Credential
Import-Module MsOnline
Connect-MsolService -Credential $credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “” -Credential $credential -Authentication “Basic” -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking
Now just SAVE this file, ensure PowerShell is closed and then reopen PowerShell.
Now you should have a prompt for credentials when you open PowerShell to connect to Exchange Online and Office 365. Enter the credentials and wait a few seconds while PowerShell loads the appropriate modules.

Leave a Reply

Your email address will not be published. Required fields are marked *