Created
March 1, 2016 00:07
-
-
Save chrisbrownie/64ba2ba585358757a738 to your computer and use it in GitHub Desktop.
Connects PowerShell to Office 365 Exchange Online
This file contains hidden or 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
function Connect-ExchangeOnline() { | |
Param( | |
$Credential = $(Get-Credential) | |
) | |
if (-not $global:eoSession) { | |
$Global:eoSession = New-PSSession ` | |
-ConfigurationName Microsoft.Exchange ` | |
-ConnectionUri "https://outlook.office365.com/powershell-liveid" ` | |
-Authentication Basic ` | |
-AllowRedirection ` | |
-Credential $Credential | |
if ($global:eoSession) { | |
Import-PSSession $Global:eoSession | |
} else { | |
throw "Unable to connect to Exchange Online!" | |
} | |
} else { | |
throw "Already connected to Exchange Online! Run Disconnect-ExchangeOnline first" | |
} | |
} | |
function Disconnect-ExchangeOnline() { | |
if ($global:eoSession) { | |
Remove-PSSession $global:eoSession | |
} else { | |
Write-Warning "Not currently connected to Exchange Online" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment