Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get IIS log location via powershell?

I'm writing a script that I'd like to be able to easily move between IIS servers to analyze logs, but these servers store the logs in different places. Some on C:/ some on D:/ some in W3SVC1, some in W3SVC3. I'd like to be able to have powershell look this information up itself rather than having to manually edit this on each server. (Yeah, I'm a lazy sysadmin. #automateallthethings.)

Is this information available to PowerShell if I maybe pass the domain to it or something?

like image 703
Josiah Avatar asked Nov 06 '14 16:11

Josiah


1 Answers

I found this to work for me since I want to know all of the sites log directory.

Import-Module WebAdministration

foreach($WebSite in $(get-website))
    {
    $logFile="$($Website.logFile.directory)\w3svc$($website.id)".replace("%SystemDrive%",$env:SystemDrive)
    Write-host "$($WebSite.name) [$logfile]"
    } 

like image 92
Craig Pero Avatar answered Nov 10 '22 11:11

Craig Pero