I need to retreive how many sites are active in a web application using either powershell code or console application. Require the code ( also need how many users have accessed the active site collections if possible)?
I don't know about active site collections, but to list all your site collections in a specific web application, run PowerShell as admin and type
Get-SPWebApplication http://yourApp/ | Get-SPSite
If you got a lot of site collections in a web application you can add the parameter
-limit all to
About the last 10 users who visited the site collection, check your old post.
You may need to define what you mean by Active. If it is simply viewing a site then it is difficult but if it is some edit been done in the site then you should try to use
SPWeb.LastItemModifiedDate to get the date any item was modified in the site and based on the return date you can judge whether the site has been active or not.