Connect to SharePoint Online Site using PowerShell

In this PowerShell SharePoint tutorial, we will discuss how to connect to a SharePoint Online site using PowerShell. We will see, how to connect to SharePoint Online Office 365 site using SharePoint Online Management Shell.

Connect to SharePoint Online Site using SharePoint Online Management Shell

To work with SharePoint Online using Online management shell, we need to download and install the “SharePoint Online management shell” in each system from which you want to connect to your SharePoint Online.

We can use SharePoint Online Management Shell to manage SharePoint Online users, sites, and site collections, lists, libraries, etc. SharePoint Online Management Shell commands differ from Office 365 Commands.

Office 365 commands manage Office 365-level tasks such as users, licenses, organization information, and services.

Regarding permission, to use SharePoint Online PowerShell commands, you must be a SharePoint Online global administrator.

To use the SharePoint Online management shell we need to download and install SharePoint Online Management Shell.

Download SharePoint Online Management Shell:

First, download SharePoint Online Management Shell from this MSDN URL.

Click on the download button and then choose the particular version (64 bit or 32 bit).

Then click on the installer to install the SharePoint Online management shell.

Connect to SharePoint Online Site using PowerShell
Connect to SharePoint Online Site using PowerShell

Once it is installed successfully, it will show the completion wizard.

After this, if you will search for “SharePoint Online Management Shell”, we can see the management shell available.

How to connect to SharePoint online site using SharePoint Online Management Shell

Now you can open the SharePoint Online management shell and run the below command to connect to SharePoint Online.

Connect-SPOService -Url https://<tenantname>-admin.sharepoint.com -credential yourusername@<tenantname>.onmicrosoft.com

Once you run the command it will ask for a password and then it will connect to SharePoint online site. Remember the user must be a SharePoint Online global administrator to use SharePoint Online PowerShell commands.

connect to sharepoint online site using sharepoint online management shell
Connect to SharePoint Online Site using PowerShell
connect to sharepoint online site using sharepoint online management shell
Connect to SharePoint Online Site using PowerShell

Connect to SharePoint Online Site using Windows PowerShell ISE

We can also connect to SharePoint Online Office 365 sites using Windows PowerShell ISE. For that, we have to import “Microsoft.Online.SharePoint.PowerShell” like below:

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

And then we can use the Connect-SPOService command like below:

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://<tenantname>-admin.sharepoint.com -credential yourusername@<tenantname>.onmicrosoft.com

Once you run the above command, it will ask for the password and once you enter the password and click on OK, it will connect to the site.

connect to sharepoint online site using powershell
SharePoint Online management shell

To test it you can run the below command.
Get-SPOSite

See also  How to create a custom master page in SharePoint using design manager

This will return all the site collections from your Office 365 tenant like below:

connect to sharepoint online site using powershell
SharePoint Online management shell

Current site is not a tenant administration site

If you got an error like Connect-SPOService : Current site is not a tenant administration site.

Then check [Solved] Connect-SPOService : Current site is not a tenant administration site

I hope this SharePoint tutorial explains, how to connect to the SharePoint Online site from PowerShell or from the SharePoint Online management shell.

You may like the following PowerShell SharePoint Online tutorials:

>