We are trying to fetch all site collections in our SP Online tenant using the below code.
SPOSitePropertiesEnumerable prop = null;
prop = tenant.GetSitePropertiesFromSharePoint("0", true);
ctx.Load(prop);
ctx.ExecuteQuery();
List<SiteProperty> AllSiteVals = new List<SiteProperty>();
foreach (SiteProperties sp in prop)
{
flag++;
SiteProperty siteDetail = new SiteProperty
{
SiteTitle = sp.Title,
SiteUrl = sp.Url
};
AllSiteVals.Add(siteDetail);
}
However we see a huge discrepancy in the number of site collections being fetched from code (around 1450) and from the admin center (around 3600). We verified that we are missing many site collections which we should not.
How do we fix this?
To fix this issue we also tried looping thru using prop = tenant.GetSiteProperties(flag, true);
Issue is we get 265 sites in the first iteration and then it moves out of the loop.