How to connect to and manage Office365 using PowerShell

Office365

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

  1. Install Microsoft Online Services Sign-in Assistant link
  2. Install Azure Active Directory Module link
  3. Install SharePoint Online Management Shell link
  4. Install Skype for Business Online Module link
  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)
  6. Change the PowerShell execution policy to remote signed
  7. Run the script.

Windows PowerShell connected to Office365 get-module

Full instructions

  1. Download and install the Microsoft Online Services Sign-in Assistant link.

Microsoft Online Services Sign-In Assistant Download

Select the correct version for your OS.

Microsoft Online Services Sign-In Assistant - choose the download you want

Save the file.

MSOIDCLI_64.msi save fileRun the installer.

Microsoft Online Services Sign-In Assistant License AgreementMicrosoft Online Services Sign-In Assistant Finished setup wizard

2. Download and install Azure Active Directory Module link.

Since October 2014 this is now only availble in 64-bit version. Save the file.

Save Azure Active Directory ModuleRun the installer.

Install WIndows Azure Active Directory Module for Windows PowerSHell

Windows Azure Active Directory Module for Windows PowerShell License Terms

Windows Azure Active Directory Module for Windows PowerShell INstall Location

Windows Azure Active Directory Module for Windows PowerShell Ready to Install

Windows Azure Active Directory Module for Windows PowerShell Finished Setup

3. Install SharePoint Online Management Shell link.

SharePoint Online Management Shell downloadSelect the correct version for your OS.

SharePoint Online Management Shell download - choose the version you requireSave the file.

SharePoint Online Management Shell download 4630-1200Run the installer.

SharePoint Online Management Shell License Agreement

SharePoint Online Management Shell Finished Setup

4. Install Skype for Business Online Module link.

Skype for Business Online Windows PowerShell Module download

Save the file.

Download Skype for Business Online Windows PowerShell Module - Save File

Run the installer.

Skype for Business Online Windows PowerShell Module - License Agreement

Skype for Business Online Windows PowerShell Module - Install Successful

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

Windows PowerShell set-executionpolicy -executionpolicy remotesignedRun the script. Enter your Office365 credentials.

office365connection enter credentialsDepending on your setup you’ll see a screen similar to the one below.

Windows PowerShell connected to Office365

Your now connected to Office365 with PowerShell.

Type Get-Module to see the loaded modules.

Windows PowerShell connected to Office365 get-module

Resource:

powershell.office.com

Related Posts:

1. Exchange PowerShell: How to Bulk Import/Create Mail Contacts

2. Office365 PowerShell: How to the find out mailbox sizes in Office365 (and Exchange 2016) using PowerShell

3. How to install Exchange 2013 (SP1) on Windows Server 2012 R2

4. Exchange 2013 Initial Configuration Settings

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.