[SP2013] Getting a list of site collections using search

Getting a list of site collections from SharePoint 2013 sounds like a pretty trivial task of which you would say the client side object model is capable of handling. Well when you’re chatting with Office365 it is. And even when you’re on-premises, there’s some hacking you can do in order to utilize the same tenant-based solution. Vesa Juvonen detailed here what you need to do first (the part about setting a site collections AdministrationSiteType¬†property).

But what if you’re chatting against an on-prem environment, but are not allowed to make these kind of (Powershell) changes? Well in that case your only option left is to query search for the list of site collections it knows about. Be aware that this is not bullet proof! It’s depending on the search index and it will security trim any sites you do not have access to (so use an account that has access on webapplication level). Also, search is limited to giving back a maximum of 500 results per query. Fortunately, there’s some paging logic you can use to get the entire collection back in batches. If you’re interested, check out the following code snippet.



Leave a Reply

Your email address will not be published. Required fields are marked *