Very simple set of lines to connect to Office 365’s Exchange Online management in PowerShell. Once connected using the below you can then start running commands such as Get-Mailbox etc.
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking