Open-MSOLConnection.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function Open-MSOLConnection
{
  <#
    .SYNOPSIS
    Connects and loads a MSOL PoSH Connection.
    .DESCRIPTION
    Gets credential for MSOL Session, configures a new session and loads it.
    .EXAMPLE
    Open-MSOLConnection
    #>

  $LiveCred = Get-Credential
  $Session = New-PSSession -Name MSOL -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/PowerShell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
  Import-Module (Import-PSSession $Session -AllowClobber) -Global
  connect-msolservice -credential $LiveCred
}