How to connect to a specific SharePoint site via PowerShell

How to connect to a specific SharePoint site via PowerShell

If you want to connect to a specific SharePoint site with PowerShell, the recommended approach is to use PnP PowerShell and connect with Connect-PnPOnline. Microsoft’s Connect-SPOService cmdlet is used to connect to the SharePoint admin center, not directly to an individual site.

Prerequisites

Before you begin, make sure you have:

  • permission to access the SharePoint site,
  • PowerShell installed,
  • and the PnP PowerShell module installed. Microsoft describes PnP PowerShell as a PowerShell module for Microsoft 365 environments including SharePoint Online.

Install PnP PowerShell

Run the following command in PowerShell:


If prompted, confirm the installation.

Connect to a specific SharePoint site

Use the site URL with Connect-PnPOnline:


This opens a Microsoft sign-in window. After successful authentication, your PowerShell session is connected to that specific SharePoint site.

Example


Verify the connection

You can test the connection by retrieving information from the site, for example:


If the connection is successful, PowerShell returns details about the SharePoint site. PnP PowerShell includes a large set of SharePoint Online cmdlets for working with sites and related objects.

Important note about Connect-SPOService

If you use this command:


you are connecting to the SharePoint Online admin center, not to a specific site. This cmdlet is intended for SharePoint administrators and must be run against the -admin.sharepoint.com URL.

Troubleshooting

If the connection does not work:

  • verify that the site URL is correct,
  • make sure you have permission to the site,
  • confirm that the PnP PowerShell module is installed,
  • and ensure you are signing in with the correct account.