Welcome to part 4 of my SharePoint Online Management Shell series. Oh boy, it’s really getting exciting now! In today’s post, I’ll show you how to quickly enumerate Site Collections, then we’ll move onto how you apply some filters to optimise the results.


  • You must have the SharePoint Online Management Shell for Windows PowerShell installed
  • A SharePoint Online Management Shell session in PowerShell (see Part 2 of this series)
  • An open connection to SPOnline (see Part 3 of this series)


Once you have setup your SharePoint Online Management Shell session and connected to the SPOnline service, you can execute the built-in cmdlet to retrieve Site Collections:

$SPOSites = Get-SPOSite;

But wait, the default result size for this cmdlet is 200 and you have more than 200 Site Collections? Well, an old method (especially with the on-premise variant Get-SPSite) was to lift the default result size by passing the optional parameter “-Limit All”. However, with SPOnline, you’ve only got 60 seconds to complete any web service call, otherwise you’ll be hit with the following timeout error:

A timeout occurred in the web service call

So “Get-SPOSite -Limit All;” isn’t that great for larger deployments (and honestly, several hundred into the thousands of Site Collections isn’t even medium by my book), so what do we do? Well, really we can only trim our query down to filter out Site Collections not required for our workload. In fact, as annoying as it might seem on the face of it, by imposing this timeout, Microsoft are subtly forcing better and more-optimised connections. Can’t say I blame them really. Anyway, here are some examples of how to apply a filter, but won’t be guaranteed to not timeout, so experiment and optimise to suit your environment. One major limitation (at the time of writing) is that the Filter parameters only supports eq, ne, like, and notlike operators.

Example 1: Filter out Site Collections that are not “Active”:
$SPOSites = Get-SPOSite -Limit All -Filter { Status -ne "Active" };
Example 2: Filter in when the Url property is “like” keyword

$SPOSites = Get-SPOSite -Limit All -Filter { Url -like “/teams/” };

Supplementary Information

The following property values can be exposed from the Get-SPOSite cmdlet and used in your filter parameters:

  • LastContentModifiedDate
  • Status
  • ResourceUsageCurrent
  • ResourceUsageAverage
  • StorageUsageCurrent
  • LockIssue
  • WebsCount
  • CompatibilityLevel
  • Url
  • LocaleId
  • LockState
  • Owner
  • StorageQuota
  • StorageQuotaWarningLevel
  • ResourceQuota
  • ResourceQuotaWarningLevel
  • Template
  • Title
  • AllowSelfServiceUpgrade
  • DenyAddAndCustomizePages
  • SharingCapability

Once you have set up your SPOSite collection, you’ll no doubt want to start doing something with it. So next up, we’ll look at creating the ClientContext so we can invoke some CSOM workloads. Check out Part 5 of this series (coming soon).


  • Get-SPOSite cmdlet –

About the author