IIS Log file Location check Using PowerShell


Hi All,

if you want to check the IIS web site log location, You need to go to server and check the log file location.

Below is the simple power shell script, you could use on multiple servers and get the web sites Log file Location and latest log file name.

invoke-command -ComputerName Server1,Server2 -ScriptBlock {

Import-Module WebAdministration

$array =@()

foreach($WebSite in $(get-website))

{

$logFileLoc = "$($Website.logFile.directory)\w3svc$($website.id)".replace("%SystemDrive%",$env:SystemDrive)

$latestLogFileName =Get-ChildItem -path $logFileLoc |Sort-Object LastWriteTimeUtc -Descending |select -First 1

$array += [pscustomobject] [ordered] @{ # Only if on PowerShell V3

ServerName=$env:computername

WebsiteName = $($WebSite.name)

LogFileLocation = $logFileLoc

LatestLogFileName = $($latestLogFileName.BaseName)

}

}

$array

}| Select-Object * -ExcludeProperty RunspaceId, PSComputerName |Out-GridView

Regards,

Chaitanya

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free