Read time: 8 minutes
In Microsoft 365 SharePoint, you may need to check several SharePoint sites, review their settings, or perform the same administrative task across multiple site collections. To do such tasks through the interface, you can easily imagine how long it may take and how cumbersome it is with the SharePoint admin center.
However, you can use PowerShell to automate and handle many of these tasks more directly. Instead of repeating the same clicks, you can run commands to retrieve information and manage supported settings, along with automating routine work. To learn how to connect to SharePoint Online using PowerShell, PnP PowerShell, and Graph PowerShell, and verify the connection as well, stay with us here.
What is SharePoint Online Management Shell?
SharePoint Online Management Shell is Microsoft’s PowerShell module for administering SharePoint Online. It provides a set of cmdlets for supported tenant-level administrative tasks, including managing site collections and configuring SharePoint settings. The main connection command is Connect-SPOService. It connects an admin to the SharePoint admin center and allows them to run supported SharePoint Online cmdlets to get the job done. However, you must disconnect PowerShell from the admin center once you have performed what you want. For that, Disconnect-SPOService is the needed command.
Prerequisites for Connecting to SharePoint Online via PowerShell
Before running the commands to connect to SharePoint Online, make sure you have:
- A Microsoft 365 account that can sign in to your organization’s tenant
- The required SharePoint admin role, such as SharePoint Admin or Global Admin role
- Correct SharePoint admin center URL (https://yourtenant-admin.sharepoint.com)
- The SharePoint Online Management Shell module installed on your computer
- An authentication method that complies with your organization’s security policies
Step-by-Step Process: Connect to SharePoint Online Using PowerShell
Here is the complete set of commands from installation to connection and disconnection. Understand them and execute them to connect to SharePoint Online PowerShell:
Step 1: Open PowerShell and run the command below to check your PowerShell version
Step 2: To install the SharePoint Online Management Shell module, run this command:
If PowerShell asks you to approve installation from the PowerShell Gallery, verify the repository before proceeding.
To update an existing installation, run:
Update-Module -Name Microsoft.Online.SharePoint.PowerShell
If the module is not installed, use the installation command instead.
Step 3: Now run the command below to connect to the SharePoint admin center:
Replace the sample URL with your actual SharePoint admin center URL.
Step 4: PowerShell will ask you to sign in. Enter your Microsoft 365 account details and complete any additional authentication steps, such as MFA.
Step 5: After signing in, run a read-only command to verify the connection:

Step 6: Once connected, you can run supported SharePoint Online Management Shell cmdlets.
- Get-SPOSite: It will retrieve site collection information.
- Set-SPOHomeSite: It will set the SharePoint Site as the Home Site.
- Set-SPOTenant: It will set the properties on the SharePoint Online tenant.
- Set-SPOUser: It will set various properties on an active user.
- Test-SPOSite: It will evaluate the SharePoint Online site collection.
- Upgrade-SPOSite: It will initialize an upgrade process for the SharePoint Online site collections.
- Export-SPOUserProfile: It will export the selected user profile to a CSV file.
- Get-SPOAppErrors: If there is an error in the SharePoint Online account, it will show it.
- Enable-SPOCommSite: The command creates a communication site experience on a previously existing classic team site.
- New-SPOSiteGroup: It will create a new site group for the SharePoint Online account collection.
- Remove-SPODeletedSite: The command will remove a SharePoint Site by deleting it from the recycle bin.
- Add-SPOSiteDesign: It will create a new site design for the users when they create a new site.
- Repair-SPOSite: It will check the sites and repair minor issues.
- Disconnect-SPOService: It will disconnect the SharePoint Online Service.
Use the relevant cmdlet for the task you need to complete, and review its parameters before changing tenant settings or site configurations.
Step 7: When you are set to finish, you can close the PowerShell session. Run the command below:
How to Connect to SharePoint Online using PnP PowerShell
For site and data management, PnP (Patterns and Practices) PowerShell can also be used to connect to SharePoint Online. It is highly popular because it allows you to connect directly to specific site collections. Here are the steps and commands to follow:
Step 1: Open PowerShell and run the command below to install the PnP Module:
Step 2: Now run the command below to connect to a specific SharePoint Site
The –Interactive switch triggers a modern authentication web browser pop-up that supports MFA. Input your credentials and confirm the connection.
Step 3: Verify the Connection by fetching the lists inside that specific site using the command below:
Can I Connect to SharePoint Online Using Modern Authentication?
Yes. You can and must connect to SharePoint Online using modern authentication (OAuth and OpenID Connect). This is because Microsoft has permanently blocked legacy client and basic authentication protocols.
While connecting, admins may encounter the error Could not connect to SharePoint Online even when the admin URL is correct. For this, there can be a problem with authentication configuration that blocks the authentication flow being used. To get rid of this, make sure that your installed module version supports the required parameters. For an applicable federated authentication scenario, the connection can use:
Connect-SPOService -Url “https://YourTenan-admin.sharepoint.com” -ModernAuth $true -AuthenticationUrl “https://login.microsoftonline.com/organizations”
Replace the example URL with your tenant’s admin center URL.
The -ModernAuth and -AuthenticationUrl parameters should be used when appropriate for your environment.
You can also try the system-browser authentication option if your installed module supports it:
-Url https://YourTenant-admin.sharepoint.com
-UseSystemBrowser $true
This uses the system browser for the sign-in process. You must still meet your organization’s authentication and access requirements.
Can I Connect to SharePoint Online Using Microsoft Graph PowerShell
Yes, you can connect to SharePoint Online using Microsoft Graph PowerShell. It is another option when your task involves resources exposed through Microsoft Graph APIs. Here are the cmdlets to connect to SharePoint Online using Microsoft Graph PowerShell:
Step 1: Run the command below to install the Graph PowerShell SDK:
Step 2: Connect with the required delegated permission:
Step 3: After that, complete the sign-in and consent process required by your organization’s policies.
Once connected successfully, you can use supported Graph cmdlets to work with SharePoint resources.
Final Thoughts
We hope you now understand how to connect to SharePoint Online using PowerShell cmdlets. It becomes simpler if you have all prerequisites, the correct module, the admin center URL, and needed permissions. With SharePoint Online Management Shell, you can not only manage the existing accounts and sites, but also create more site collections, assign permissions, migrate site collections, and delete various parts.
When planning for tenant consolidation, business merger, department separation, or such other tasks, migrating SharePoint Online via PowerShell can be complex. Moreover, a SharePoint migration tool can reduce the hassle of exporting data from one tenant to another.
