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.
Full instructions
- 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.
Select the correct version for your OS.
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.
Import-Module MSOnline
#Establishes Online Services connection to Office 365 Management Layer.
Connect-MsolService -Credential $credential
#Imports the installed Skype for Business Online services module.
Import-Module LyncOnlineConnector
#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.
Import-PSSession $lyncSession
#Imports SharePoint Online session commands into your local Windows PowerShell session.
Import-Module Microsoft.Online.Sharepoint.PowerShell
#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.
Import-PSSession $ExchangeSession
6. Run Windows PowerShell as Administrator.
Tyep the command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Run the script. Enter your Office365 credentials.
Depending on your setup you’ll see a screen similar to the one below.
Your now connected to Office365 with PowerShell.
Type Get-Module to see the loaded modules.
Resource:
Related Posts:
1. Exchange PowerShell: How to Bulk Import/Create Mail Contacts
3. How to install Exchange 2013 (SP1) on Windows Server 2012 R2