Hi MichaelHan-MSFT,
If you want to enumerate all sites including modern sites, please take a reference of the below method:
In the tenant admin site, there is a hidden list named DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS that store a copy of aggregated site collections data from all contentdb.
You can get it like below:
var siteurl = "https://tenant-admin.sharepoint.com" // Tenant site!
List AllSiteList = Context.Web.Lists.GetByTitle("DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS");
ListItemCollection AllSiteItems = AllSiteList.GetItems(CamlQuery.CreateAllItemsQuery());
Context.Load(AllSiteItems);
Context.ExecuteQuery();
The corresponding rest api is:
/_api/web/lists/getbytitle('DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS')/items
Best Regards,
Baker Kong
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.