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.
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.
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 [email protected]<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 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 [email protected]<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.
To test it you can run the below command.
This will return all the site collections from your Office 365 tenant like below:
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 the following PowerShell SharePoint Online tutorials:
- Getting Started with PnP PowerShell – SharePoint 2013/2016/SharePoint Online
- Bulk SharePoint Online Site Collection Creation using PowerShell
- The remote server returned an error (401) Unauthorized SharePoint online management shell error
- Create List or Document Library using PowerShell in SharePoint Online
- Add items from CSV file to SharePoint Online List using PowerShell in CSOM
- Create Site Collection in SharePoint Online using PowerShell
Hope this SharePoint tutorial explains, how to connect to the SharePoint Online site from PowerShell or from the SharePoint Online management shell.
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Out audiences are from the United States, Canada, United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a SharePoint MVP(8 times), check out My MVP Profile. I have also worked in companies like HP, TCS, KPIT, etc.