Last active
August 4, 2017 07:33
-
-
Save Windos/5f96a9425b5b31c23df441035b478c5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 3.0 | |
#Requires -Modules MSOnline, SkypeOnlineConnector, Microsoft.Online.SharePoint.PowerShell | |
<# | |
Required downloads | |
Microsoft Azure Active Directory Module for Windows PowerShell | |
32-bit: http://aka.ms/fohrds | |
64-bit: http://aka.ms/siqtee | |
Skype for Business Online Connector: http://aka.ms/x3kyib | |
SharePoint Online Management Shell: http://aka.ms/f04q5o | |
Microsoft Online Services Sign-In Assistant (if Win7): http://aka.ms/vl42dg | |
#> | |
function Connect-O365Services { | |
param ( | |
[Parameter(Mandatory = $true, | |
Position = 0)] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$Tenant, | |
[Parameter(Mandatory = $true, | |
Position = 1)] | |
[ValidateNotNullOrEmpty()] | |
[System.Management.Automation.PSCredential] | |
[System.Management.Automation.Credential()] | |
$Credential | |
) | |
# Connect to Office 365 | |
Connect-MsolService -Credential $Credential | |
# Connect to Exchange Online | |
$Script:ExSession = New-PSSession -Credential $Credential -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Authentication "Basic" -AllowRedirection -ErrorAction SilentlyContinue | |
if ($Script:ExSession) { | |
Import-PSSession $Script:ExSession | |
} | |
# Connect to SharePoint Online | |
Connect-SPOService -Credential $Credential -Url "https://$Tenant-admin.sharepoint.com" -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