This post is a contribution from Aaron Miao, an engineer with the SharePoint Developer Support team
Like myself, many of you may like the SharePoint Online API GetSiteProperties that lists all site collections of a SharePoint Online tenant. Unfortunately, as you know, the method was only available to SharePoint Online, although the document does not explicitly remark this.
Now the good news is that SharePoint team has made the same method available to SharePoint Server 2016 on-premises! You can get this from SharePoint 2016 October PU.
Here’s the sample code you could find online out there.
For SharePoint Online, the code will just work. However, for SharePoint 2016 on-premises, you need to follow the steps below to set environment.
Please follow Provisioning site collections using SP App model in on-premises with just CSOM post for a more details.
Here’re the required steps:
- Install October 2016 PU for SharePoint 2016 to your SharePoint 2016 farm.
- Download SharePoint Server 2016 Client Components SDK that to your remote development environment where you write your CSOM code This contains 16 version of the objects which are also needed with SP2016 on-premises. These are located in the Online.SharePoint.Client.Tenant.dll assembly, which is by default installed to C:\Program Files\SharePoint Client Components\16.0\Assemblies folder.
- Enable Tenant admin server stub using just CSOM by running PowerShell script below.
- Enable AdministrationSiteType property from one site collection in your on-premises farm which will be acting like a admin site. This could be, for example, root site in the root site collection of the web application where you call the new API on it.
Namespace Microsoft.Online.SharePoint.TenantAdministration (in Microsoft.Online.SharePoint.Client.Tenant.dll) introduces new set of client APIs to SharePoint 2016 on-premises. However, please note that it is not identical to SharePoint Online version.