Connect to the different Office 365 services through PowerShell (Exchange Online, Skype for Business, SharePoint Online)

In this post I will explain how to establish a connection to Exchange Online, Skype for Business Online and SharePoint Online in PowerShell. It’s pretty straight forward but you need to have the right pre-requisites installed.

Exchange Online

To connect to Exchange Online admin run the following script and provide the username and password for an admin user.

$UserCredential = Get-Credential
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $ExchangeSession

Run the command below to verify that the connection to Exchange Online was established. This command should return all mailboxes in your Exchange Online organization.

Get-Mailbox

Skype for Business Online

Requirements

  1. OS needs to be Windows 7 or later (Windows 8, Windows 8.1, Windows 10) / Windows Server 2008 R2 or later (Windows Server 2012, Windows Server 2012 R2, Windows Server 2016)
  2. Windows PowerShell 3.0 – Install Windows Management Framework 3.0 (or newer) which includes Windows PowerShell 3.0
    • Check what version you have by running the PowerShell command below.
      Get-Host | Select-Object Version
    • This is preinstalled on Windows 8 and above and Windows Server 2012 and above.
  3. Skype for Business Online Connector Module

Establish connection

To connect to Skype for Business Online admin run the following script and provide the username and password for an admin user.

Import-Module LyncOnlineConnector

$credential = get-credential
$skypeSession = New-CsOnlineSession -Credential $credential
Import-PSSession $skypeSession

Run the command below to verify that the connection to Skype for Business Online was established. The command should return all Skype for Business users in your tenant.

Get-CsOnlineUser

SharePoint Online

Requirements

  1. OS needs to be Windows 7 SP1 or later (Windows 8, Windows 8.1, Windows 10) / Windows Server 2008 R2 SP1 or later (Windows Server 2012, Windows Server 2012 R2, Windows Server 2016).
  2. SharePoint Online Management Shell

Establish connection

To connect to SharePoint Online admin, alter the URL in the script below, run it and provide the username and password for an admin user.

Import-Module Microsoft.Online.Sharepoint.PowerShell

$credential = Get-credential

#Replace the URL with your SharePoint Online admin site
Connect-SPOService -url https://contoso-admin.sharepoint.com -Credential $credential

You can find the admin URL by entering SharePoint Online admin in the Office 365 admin portal and looking at the URL. To verify that you were able to connect to SharePoint Online you can run the command below which should list all site collections in the tenant.

Get-SPOSite

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.