How do I find the last time a web site was accessed
-
Friday, May 04, 2012 9:46 PM
So now that I know how to find all the web sites on a remote server, I need to determine the last time some one accessed that site.
I have found one web site that discusis this, but it appears that the answer is written in C# with some sort of library that needs to be attached or complied. I must admit I am clueless about C#.
And this appears to be for Sharepoint sites. I need this info for any and all web sites.
Is there anyway to do this in Powershell?
All Replies
-
Saturday, May 05, 2012 4:02 AM
the web site is essentially files on a computer. could you not just use find the root directory of the site and use get-childitem to get the last access time of the folders?
-
Saturday, May 05, 2012 4:51 AM
IMHO date info for folders is sometimes misleading. Might work for key files, however, last accessed date will be updated for *any* access, not just through the web. If some background process happens to periodically upload files for example. Or if the developer/maintainer takes a copy to start developing version 2.
I would think that the best approach would be for the site to run script that logs accesses. This would probably be better done through server side scripting, rather than client side.
Al Dunbar
-
Saturday, May 05, 2012 5:19 AM
You can use log parser tool to find out that. You may refer below thread to create batches / Scripts. You can run those batches on IIS logs.
Sunil Pathare SR. System Admin
- Edited by Sunil Pathare Saturday, May 05, 2012 5:19 AM
-
Saturday, May 05, 2012 5:19 PMTo clarify my purpose here. There are over 4500 servers in our domain that have IIS installed. Management wants to know how many of these are actually being used to serve web sites and how many are just "installed". If they are being used to serve a web site or web sites, when was the last time they were accessed? So, if a developer hits it, that counts. Or " If some background process happens to periodically upload files" that would count as well.
-
Saturday, May 05, 2012 5:26 PM
" find the root directory of the site "
If a web server has multiple sites, how do you determine which directory belongs to which site?
Sorry for the really basic questions, but IIS is a bit of a mystery to me.
-
Monday, May 07, 2012 4:01 AM
Every file which you are accessing is counted as a hit. To find out directory of website
Run > Inetmgr > Expand Websites > Right Click on any website > check Home Directory Tab
Sunil Pathare SR. System Admin
-
Monday, May 07, 2012 12:48 PM
my take on this...
$results = @() $servers = gc server.txt foreach($server in $servers) { $iis = [adsi]"IIS://$server/w3SVC" $sites = $iis.Children | ?{$_.keytype -eq "IIsWebServer"} foreach($site in $sites) { $logdir = $site.LogFileDirectory $logdir = $logdir -replace ':\\', '$\' $logdir = "\\$server\$logdir\w3svc$($site.name)" if(Test-Path $logdir) { $lwt = gci $logdir | sort lastwritetime -Descending | select -first 1 -ExpandProperty lastwritetime $daysago = (New-TimeSpan -Start $lwt -End ([datetime]::Now)).days $obj = New-Object psobject -Property @{ Server=$server Site = $($Site.name) Comment = $($site.ServerComment) LastUsed = $lwt DaysAgo = $daysago } $results += $obj } } }I should add, I tested this in V3 but im pretty sure there is nothing V3 specific in here, also i only tested it on one working server, might need to add some error trapping in there
Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

