# Connect to all Office 365 services in a single Windows PowerShell window # Based on the TechNet article at https://technet.microsoft.com/en-us/library/dn568015.aspx. # # Connects to Azure, ExO, SpO, and SfB in one script. Switches are provided to omit connecting to a particular service. # # NOTE: # Requires a PowerShell profile to be setup with the variables and functions located at https://pastebin.com/dpdmkhHq Param( [string] $TenantName = "dur10", # The SHORT name for your tenant. Omit the .onmicrosoft.com part. [string] $UserName = "admin@tylerdurh.am", # An admin UID for your tenant. [switch] $Exchange, # Specify this switch to ignore connecting to Exchange Online. [switch] $All, [switch] $SCCenter, # Specify this switch to ignore connecting to Security & Compliance Center. [switch] $SharePoint, # Specify this switch to ignore connecting to SharePoint Online. [switch] $Skype # Specify this switch to ignore connecting to Skype for Business Online. ) $cred = Get-StoredCredential -UserName $UserName Write-Output "Connecting to Azure AD..." Connect-AzureAD -Credential $cred # EXCHANGE ONLINE if ( $Exchange.IsPresent -eq $true -or $All.IsPresent -eq $true ) { Write-Output "Connecting to Exchange Online..." $ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication "Basic" -AllowRedirection Import-PSSession $ExchangeSession -AllowClobber } if ( $SCCenter.IsPresent -eq $true -or $All.IsPresent -eq $true ) { Write-Output "Connecting to Security & Compliance Center..." $SCCenterSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection Import-PSSession $SCCenterSession -AllowClobber } # SHAREPOINT ONLINE if ( $SharePoint.IsPresent -eq $true -or $All.IsPresent -eq $true ) { $url = ( "https://" + $TenantName + "-admin.sharepoint.com" ) Write-Output "Connecting to SharePoint Online at $url..." Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking Connect-SPOService -Url $url -credential $cred } # SKYPE FOR BUSINESS if ( $Skype.IsPresent -eq $true -or $All.IsPresent -eq $true ) { Write-Output "Connecting to Skype for Business..." Import-Module SkypeOnlineConnector $SkypeSession = New-CsOnlineSession -Credential $cred Import-PSSession $SkypeSession -AllowClobber }