Getting all site collections with csom does not work when created with new office admin portal

I can retrive all site collection information with the following code:

Tenant tenant = new Tenant(ctx);
props = tenant.GetSiteProperties(0, true);
ctx.Load(props);
ctx.ExecuteQuery();
foreach (SiteProperties sp in props) {...}

But when I create a new site collection with the new Office 365 admin portal, the created site collections are not listed in props. I can only see the one created with the old admin portal.

Did I miss sth?

1 answer

  • answered 2019-06-25 06:57 LZ_MSFT

    We can use Tenant.GetSitePropertiesFromSharePoint method to achieve it. The Tenant.GetSiteProperties method won't return the Site Collections created on new modern site templates.

    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());
    }
    

    Reference: Get All Site Collections from SharePoint Online Tenant