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
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
2 thoughts on “PnP PowerShell to get all Site Collections”