Connect to Office 365 via PowerShell

1. Allowing PowerShell executing scripts:

2. Do this in an elevated PowerShell promt:
$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Allowing PowerShell executing scripts

By default PowerShell is restricted to not allow script execution. To allow script execution do the following

Open PowerShell in elevated mode (run as administrator) and run the following command:
Set-ExecutionPolicy unrestricted

To verifiy how if script execution is allowed or not run the following command in PoweShell: