//using Microsoft.SharePoint.Client;
//using Microsoft.Online.SharePoint.TenantAdministration;
//string weburl = "https://site-admin.sharepoint.com";
//GetSiteCollections(credentials, weburl);
//This method returns the count of Site Collections available in the tenant
//Also returns thr url of all site collections
private static void GetSiteCollections(SharePointOnlineCredentials credentials, string weburl)
{
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
Tenant tenant = new Tenant(ctx);
SPOSitePropertiesEnumerable siteCollections = tenant.GetSiteProperties(0, true);
ctx.Load(siteCollections);
ctx.ExecuteQuery();
Console.WriteLine("Total Site Collections in tenant: " + siteCollections.Count.ToString());
foreach (SiteProperties site in siteCollections)
{
Console.WriteLine(site.Url.ToString());
}
}
Console.WriteLine("Press any key to exit...");
Console.Read();
}This Code snippets helps to retrieve the list of site collections available in SharePoint Online Tenant.
