search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Getting IIS Log Files with PowerShell
Posted in Hosting & IIS7, Windows Powershell | 1 Comment | 4,922 views | 16/01/2015 14:01

You can get active IIS log file paths with following script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Get Web Sites
$WebSites = Get-Website | Select Name, Id, LogFile
 
foreach ($WebSite in $WebSites)
{
	# Clear Variables
	$LogFiles = $Null;
	$LogFilePath = $Null;
 
	# Get Web Site Information
	$SiteName = $WebSite.Name
	$SiteID = $WebSite.Id
 
	# Get Web Site Log Path
	$LogDirectory = $WebSite.LogFile.Directory -Replace '%SystemDrive%', $env:SystemDrive
	$LogPath = $LogDirectory + "\W3SVC" +  $SiteID
	$LogFiles = Get-ChildItem $LogPath -Filter *.log -EA SilentlyContinue | Sort-Object LastWriteTime -Descending
	if ($LogFiles) { $LogFilePath = $LogFiles[0].FullName; $LogFilePath; }
}

That will give you path as an output.


Comments (1)

Hjunior

May 16th, 2018
16:48:20

Thanks a lot!



Leave a Reply