Use PowerShell to log into Office 365 Exchange

How to log into Office365 Exchange or on-premise Exchange server using PowerShell.