Connect to SharePoint Online Site using PowerShell

SharePoint Online PowerShell
SharePoint deveopment training course

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 “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 differs 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

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 sharepoint online management shell

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

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

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

connect to sharepoint online site using powershell

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

You may like following PowerShell SharePoint Online tutorials:

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

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →