I need to retreive last 10 users who have logged in a site.(I need to chek in each site under a webapp who are the last 10 users to log in). and export it to a csv file.Require code in powershell.

1 Answer 1


Easiest thing would be to use logparser for IIS to retrieve this information and it does the job of exporting to csv and sql.

logparser -i:IISW3C "select date,time,c-ip,cs-username,cs-uri-stem INTO myfilename.csv from \\ \c$\inetpub\logs\LogFiles\W3SVC979930197\*.log where sc-status = 200 AND cs-username IS NOT null AND cs-uri-stem LIKE '%sites/yoursitecollection' AND cs-method = 'GET' AND to_timestamp(date,time) between timestamp('2013/07/08 00:00:00', 'yyyy/MM/dd hh:mm:ss') and timestamp('2013/07/09 23:59:00', 'yyyy/MM/dd hh:mm:ss')

Replace with your WFE ip address. You can create a batch file and run it from a single server to consolidate log reports from all your WFEs. Merge the csv files through dos copy command and voila you will have the report of all users who logged into your site collection between a specific period of time that you mention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.