In this post I’ll look at how to connect to Office365 using PowerShell.
I’m working with a few more companies now who use Office365 so I thought I would look at how to connect to Office365 using PowerShell so that I can manage and maintain them more easliy.
While powershell.office.com looks like it will be an invaluable source of information, when I was just getting started with connecting to Office365 with PowerShell, I just want to get connected, take a look around and start managing. So here is a quick guide.
Quick Start instructions
- Install Microsoft Online Services Sign-in Assistant link
- Install Azure Active Directory Module link
- Install SharePoint Online Management Shell link
- Install Skype for Business Online Module link
- Download the connection script, rename the extension from txt to ps1 and edit the your domain for your own domain link Source (powershell.office.com)
- Change the PowerShell execution policy to remote signed
- Run the script.
- Download and install the Microsoft Online Services Sign-in Assistant link.
Select the correct version for your OS.
Save the file.
2. Download and install Azure Active Directory Module link.
Since October 2014 this is now only availble in 64-bit version. Save the file.
3. Install SharePoint Online Management Shell link.
4. Install Skype for Business Online Module link.
Save the file.
Run the installer.
5. Download the connection script, rename the extension from txt to ps1 and edit the your domain for your own domain link. Source (powershell.office.com)
#How to connect to Office 365 Cloud Services using PowerShell
#Capture administrative credential for future connections.
$credential = get-credential
#Imports the installed Azure Active Directory module.
#Establishes Online Services connection to Office 365 Management Layer.
Connect-MsolService -Credential $credential
#Imports the installed Skype for Business Online services module.
#Create a Skype for Business Powershell session using defined credential.
$lyncSession = New-CsOnlineSession -Credential $credential
#Imports Skype for Business session commands into your local Windows PowerShell session.
#Imports SharePoint Online session commands into your local Windows PowerShell session.
#This connects you to your SharePoint Online services. Replace your domain with the name of your SharePoint Online tenant.
Connect-SPOService -url https://yourdomain-admin.sharepoint.com -Credential $credential
#Creates an Exchange Online session using defined credential.
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://outlook.office365.com/powershell-liveid/” -Credential $credential -Authentication “Basic” -AllowRedirection
#This imports the Office 365 session into your active Shell.
6. Run Windows PowerShell as Administrator.
Tyep the command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Your now connected to Office365 with PowerShell.
Type Get-Module to see the loaded modules.