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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: