How to Connect to Office 365 via Powershell

This is a quick and dirty guide on how to connect to the office365 platform via powershell.

To connect to The Microsoft Office 365 Platform via Powershell you will first need to install a few prerequisites.

First start with the Microsoft Online Services Sign-In Assistant for IT Professionals RTW
https://www.microsoft.com/en-us/download/details.aspx?id=41950

Next you’ll need to install the Azure Active Directory Module for Windows PowerShell (64-bit version)
http://go.microsoft.com/fwlink/p/?linkid=236297

Then open Powershell as an administrator and run:
Set-ExecutionPolicy RemoteSigned

Now set your Office365 admin credentials
$credential = Get-Credential

Then Import the MSOnline Module
Import-Module MsOnline

Make the connection to Office 365 with
Connect-MsolService -Credential $credential

And link to exchange online with
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://outlook.office365.com/powershell-liveid/” -Credential $credential -Authentication “Basic” -AllowRedirection
and
Import-PSSession $exchangeSession

If you have sharepoint connect with
Import-Module Microsoft.Online.SharePoint.PowerShell
and
Connect-SPOService -Url https://[YOURCOMPANYDOMAINHOST]-admin.sharepoint.com -credential $credential

You can also connect to lync online with
Import-Module LyncOnlineConnector
and
$lyncSession = New-CsOnlineSession -Credential $credential
and
Import-PSSession $lyncSession

 

Done.