We can get the subsites under the site using CSOM easily but if we need to get all the site collections under a specific web application from a SharePoint farm, then we can’t get it directly. For that, we have to use SharePoint search. By using SharePoint Search, we set the “KeywordQuery” to filter and get the site collections. Before using the code block, we should ensure that the SharePoint Search Service Application is running and active.

The code block for this is mentioned below.

In this blog, I have explained how you can get all the site Collections under a SharePoint web application. I hope this blog will help you out in a few scenarios.