Public/Connect-ExchangeSession.ps1

##################################################################################################
# Connect-ExchangeSession
# Creates a session that connects to Exchange server
##################################################################################################
Function Connect-ExchangeSession(){
    #Connecting to Exchange Online
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

    #Capture administrative credential for future connections.
    $credential = get-credential

    #Creates an Exchange Online session
    $ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication  Basic -AllowRedirection

    #Import session commands
    Import-PSSession $ExchangeSession

    #Return these values so I can use the same credentials for other connections and turn off the PSSession when I am done with it
    $result = @{}
    $result.Add("Credential", $Credential)
    $result.Add("Session", $ExchangeSession)

    return $result
}