1. Open Windows PowerShell 

2.  Set-ExecutionPolicy RemoteSigned

Press Y to confirm changing the policy if prompted.

3. $Credential=Get-Credential 

4. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection 

5. Import-PSSession $Session 

6. Get-Mailbox 

7. When you end your work with Exchange 365, disconnect the session. This is the recommended practice.

Remove-PSSession $Session


[source: https://www.nakivo.com/blog/how-to-connect-office-365-exchange-online-powershell/]