How to connect to SharePoint Online Powershell

Before you can even use Powershell to manage SharePoint Online it is a prerequisite that you have installed the SharePoint Online Management Shell and that you have and can connect to SharePoint Online. After installing you can open the SharePoint Online Management Shell by going to the Start > Type sharepoint > click SharePoint Online Management Shell. You also need a account with SharePoint Online admin privileges. More information see Assign admin roles in Office 365 for business or Assign roles to user accounts with Office 365 PowerShell.

Fill in the values for the $adminUPN and $orgName variables (replacing all the text between the quotes, including the < and > characters), and then run the following commands at the SharePoint Online Management Shell command prompt:

When you get a credential request dialog box, type the password for the SharePoint Online SharePoint administrator account.

It is also possible to use Multifactor Authentication (MFA). You can do the following:

Fill in the value for the $orgName variable (replacing all the text between the quotes, including the < and > characters), and then run the following commands at the SharePoint Online Management Shell command prompt:

Follow the instructions in dialog box to provide the authentication information and click Sign in.

That’s all!

Source: TechNet