How to Connect to SharePoint Online Using PowerShell

As a SharePoint administrator, I’ve found that using PowerShell to manage SharePoint Online can save hours of tedious work. Whether you’re managing SharePoint sites, users, or content such as items or documents, PowerShell provides different cmdlets.

In this tutorial, I will demonstrate various methods for connecting to SharePoint Online using PowerShell.

Using SharePoint Online Management Shell

First, let’s understand how to connect to SharePoint Online using the SharePoint Online Management Shell.

The SharePoint Online Management Shell is Microsoft’s official PowerShell module for SharePoint Online administration.

Follow the steps below:

Step 1: Install the SharePoint Online Management Shell

Before connecting, you’ll need to install the SharePoint Online Management Shell. There are two ways to do this:

Option A: Install via PowerShell Gallery

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Option B: Download and Install Manually

You can also download the SharePoint Online Management Shell from the Microsoft Download Center and run the installer.

Step 2: Connect to SharePoint Online

Once installed, you can connect to a SharePoint Online site by using the following cmdlet.

Connect-SPOService -Url https://yourtenant-admin.sharepoint.com -Credential (Get-Credential)

This command will prompt you for your username and password. Replace “yourtenant” with your actual tenant name.

Connect-SPOService is a PowerShell cmdlet that establishes a connection between your local PowerShell session and your SharePoint Online tenant. This connection is the first crucial step before you can run any SharePoint Online administrative commands.

Think of it as opening the door to your SharePoint Online environment. Without this connection, you simply cannot access it to make changes or retrieve information.

Alternatively, you can also use the cmdlets listed below.

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

Once you run the above cmdlets, it will ask you to enter a password like below:

connect sharepoint online powershell

You can also try using the following command:

# Store credentials in a variable
$adminCredential = Get-Credential

# Connect using stored credentials
Connect-SPOService -Url "https://contoso-admin.sharepoint.com" -Credential $adminCredential

Step 3: Verify the Connection

To verify you’re connected, run a simple command:

Get-SPOSite

This should return a list of your SharePoint sites from your Microsoft 365 tenant.

connect-sposervice

Step 4: Connect With Windows PowerShell ISE

If you want to connect with Windows PowerShell ISE, then you can run the following commands:

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

Check out Turn Off Microsoft Authenticator App in Microsoft 365

Connect with Modern Authentication

Modern authentication is more secure and supports multi-factor authentication (MFA).

Step 1: Install the Required Module

Ensure you have the latest version of the SharePoint Online Management Shell. You can run the below cmdlet to update the SharePoint Online management shell.

Update-Module -Name Microsoft.Online.SharePoint.PowerShell

Step 2: Connect with Modern Authentication

Connect-SPOService -Url https://yourtenant-admin.sharepoint.com

Without specifying credentials, this will open a web-based authentication dialog where you can enter your credentials and complete any multi-factor authentication (MFA) challenges.

Here is a video tutorial that I have recorded for the same purpose.

I hope you now have a complete understanding of how to connect to SharePoint Online using the SharePoint Online Management Shell.

You may also like:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…