Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (26 sloc) 1.42 KB
This script connects to the Exchange Online admin shell.
The script checks to see if an existing Exchange Online PowerShell session exists, and doesn't attempt to reconnect if so. If no Exchange Online session is found,
the script prompts for credentials, and then connects to the Exchange Online shell, as well as the MSOL Service.
File Name : Connect-ExchangeOnline.ps1
Author : Jeremy Dahl (
Copyright 2017 - Master & Cmd-R
Simply run this script by calling .\Connect-ExchangeOnline.ps1 in PowerShell.
Write-Host "Checking for an existing connection to Exchange Online..." -ForegroundColor Yellow
$exSession = Get-PSSession | Where {$_.ComputerName -match "" -and $_.State -match "Opened"}
if ($exSession.Count -ge 1){
Write-Host "Connected!" -ForegroundColor Green
else {
#Connect to Exchange Online
Write-Host "Connecting to Exchange Online" -ForegroundColor Green
$credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $credential -Authentication Basic -AllowRedirection
$importresults = Import-PSSession $Session -AllowClobber -DisableNameChecking
Connect-MsolService -Credential $credential