Skip to content

Instantly share code, notes, and snippets.

Last active Aug 4, 2017
What would you like to do?
#Requires -Version 3.0
#Requires -Modules MSOnline, SkypeOnlineConnector, Microsoft.Online.SharePoint.PowerShell
Required downloads
Microsoft Azure Active Directory Module for Windows PowerShell
Skype for Business Online Connector:
SharePoint Online Management Shell:
Microsoft Online Services Sign-In Assistant (if Win7):
function Connect-O365Services {
param (
[Parameter(Mandatory = $true,
Position = 0)]
[Parameter(Mandatory = $true,
Position = 1)]
# Connect to Office 365
Connect-MsolService -Credential $Credential
# Connect to Exchange Online
$Script:ExSession = New-PSSession -Credential $Credential -ConfigurationName Microsoft.Exchange -ConnectionUri "" -Authentication "Basic" -AllowRedirection -ErrorAction SilentlyContinue
if ($Script:ExSession) {
Import-PSSession $Script:ExSession
# Connect to SharePoint Online
Connect-SPOService -Credential $Credential -Url "https://$" -ErrorAction SilentlyContinue
# Connect to Skype for Business Online
$Script:S4BSession = New-CSOnlineSession -Credential $Credential -ErrorAction SilentlyContinue
if ($Script:S4BSession) {
Import-PSSession $Script:S4BSession
function Disconnect-O365Services {
# Disconnect from Exchange Online
if ($Script:ExSession) {
Remove-PSSession $Script:ExSession -ErrorAction SilentlyContinue
# Disconnect from SharePoint Online
Disconnect-SPOService -ErrorAction SilentlyContinue
# Disconnect from Skype for Business Online
if ($Script:S4BSession) {
Remove-PSSession $Script:S4BSession -ErrorAction SilentlyContinue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment