Skip to content
Menu
SharePoint Gems
  • Power Platform
  • Development
    • SharePoint 2013
  • Migration
  • Administration
  • SP Online
  • Contact
  • About
    • Privacy Policy
SharePoint Gems

PnP PowerShell to get all Site Collections

Posted on August 2, 2021September 29, 2021

Hello Friends,
There was a requirement to get all site collections using PnP PowerShell in SharePoint Online. Thus in this post we will see how to get all site collections using PnP PowerShell in SharePoint online.

Retrieve all Communication Sites using PnP PowerShell

Contents hide
1 Requirement:
2 Solution:
3 By this way we can get list of all site collection using PnP PowerShell.
3.1 Share this:
3.2 Like this:
3.3 Related

Requirement:

Get all Site collections using PnP PowerShell in SharePoint online

In this post, we are going to keep it very simple. Like we will just get all site collections. In my next post, I will add the ability to exclude the site collection returned. Note: Obviously, if you don’t have access to the site collection, it will not be returned.

Solution:

Without wasting too much time, let us jump to the solution.

Retrieve all users from Site Collection using PowerShell

We are going to create a Function named GetAllSiteCollections() with the parameters as Tenant URL. So the code will look like as below.

function GetAllSiteCollections($TenantUrl,  [PSCredential] $Credentials) {
     
    Connect-PnpOnline -url $tenantUrl -Credentials $Credentials
 
    $allSiteCollections = Get-PnPSiteSearchQueryResults -All
    return $allSiteCollections
}
 
$sitecols=GetAllSiteCollections -TenantUrl https://<yourtenant>.sharepoint.com 
$sitecols

By this way we can get list of all site collection using PnP PowerShell.

You may like my other articles as well.

  • Retrieve all users from Site Collection using PowerShell
  • Check date field is empty in Nintex Workflow
  • SharePoint Online: Identify Current Page is Modern page or Classic page
  • SharePoint Online: Edit Permission Level with CSOM PowerShell
  • Retrieve all Communication Sites using PnP PowerShell
  • SharePoint Online: Delete Folders using PnP PowerShell
  • Create a Communication Site using PowerShell
  • Move SharePoint Online Files with PowerShell

Share this:

  • Print
  • Twitter
  • Facebook
  • LinkedIn
  • WhatsApp
  • Telegram
  • Pinterest
  • Reddit

Like this:

Like Loading...

Related

2 thoughts on “PnP PowerShell to get all Site Collections”

  1. Pingback: SPFx Interview Questions - SharePoint Gems
  2. Pingback: Nintex Form - Add Print Function - SharePoint Gems

Leave a ReplyCancel reply

  • Development
  • Migration
  • Poweer Apps
  • Power Automate
  • Power Platform
  • SharePoint 2013
  • SharePoint Administration
  • SharePoint Online
  • Tips
  • Uncategorized

Best of Computers

Blog Stats

  • 67,509 hits

Subscribe

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,433 other subscribers
Buy Me Coffee
©2025 SharePoint Gems | Powered by WordPress and Superb Themes!
%d