I need to know the total number of documents in our SharePoint On-Premise environment. We have SharePoint 2016 and 2013.
I found this script and tried executing it on my content databases:
SELECT COUNT(*)
FROM Docs INNER JOIN Webs On Docs.WebId = Webs.Id
INNER JOIN Sites ON Webs.SiteId = SItes.Id
WHERE
Docs.Type <> 1 AND (LeafName NOT LIKE '%.stp')
AND (LeafName NOT LIKE '%.aspx')
AND (LeafName NOT LIKE '%.xfp')
AND (LeafName NOT LIKE '%.dwp')
AND (LeafName NOT LIKE '%template%')
AND (LeafName NOT LIKE '%.inf')
AND (LeafName NOT LIKE '%.css')
However, the number count that I get seem bigger than I expect. I try to compare it with the Search Crawl logs and there's a big difference.
Will it be okay to use the search crawl log for determining the number of documents in the farm? I just need a rough estimate. If you have a PowerShell script that you can recommend then please let me know.