Hello @shraddha sawant ,
Welcome to Q&A Forum!
The snippet using the "Tenant.GetSiteProperties" method o retrieve the site collection from the SharePoint Online Tenant is as follow:
Tenant tenant = new Tenant(context);
SPOSitePropertiesEnumerable siteProps = tenant.GetSiteProperties("0", true);
context.Load(siteProps);
context.ExecuteQuery();
Console.WriteLine("Total Site Collections: " + siteProps.Count.ToString());
foreach (var site in siteProps)
{
Console.WriteLine(site.Title + "\t" + site.Template.ToString());
}
Disadvantage to this method is, it won’t return the Site Collections created on new modern site templates.
We have another method under Microsoft.Online.SharePoint.TenantAdministration namespace for retrieving all site collections created under SharePoint online Tenant is Tenant.GetSitePropertiesFromSharePoint. The snippet given below uses this method and retrieve the all Site Collections irrespective of any webtemplates.
var credentials = new SharePointOnlineCredentials(userName, password);
ClientContext context = new ClientContext(siteUrl);
context.Credentials = credentials;
Tenant tenant = new Tenant(context);
SPOSitePropertiesEnumerable siteProps = tenant.GetSitePropertiesFromSharePoint("0", true);
context.Load(siteProps);
context.ExecuteQuery();
Console.WriteLine("Total Site Collections: " + siteProps.Count.ToString());
foreach (var site in siteProps)
{
Console.WriteLine(site.Title +"\t"+ site.Template.ToString());
}
For more information, please read this post "Get All Site Collections from SharePoint Online Tenant".
**Ps:**The link you provided appears to me as 404-Page not found.
Thanks,
Echo Du
==========================
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.