Get IIS log location via powershell?

16,090

Solution 1

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]"
    } 

Solution 2

Import-Module WebAdministration

$sitename = "mysite.com"
$site = Get-Item IIS:\Sites\$sitename
$id = $site.id
$logdir = $site.logfile.directory + "\w3svc" + $id

Thanks for Chris Harris for putting the website ID idea in my head. I was able to search around better after that and it led me to the WebAdministration module and examples of its use.

Share:
16,090
Josiah
Author by

Josiah

I enjoy learning new things, digging through the potential and applying that new knowledge to problems such as modernization of aged systems. The speed and confidence that infrastructure as code, configuration management and virtualization have brought to delivering solid, dependable and predictable applications has been a real joy to be a part of. Ansible, Terraform, Docker, Kubernetes and hybrid cloud environments (AWS, GCP, On-Prem) allow for some exciting fuel for innovation, automation and simple assurance that our code runs the right way the first time every time. The promise of factory like automation through CI/CD and DevOps workflows knit this all together. It is exciting to work in that space and see the world changing. https://www.linkedin.com/in/josiahritchie

Updated on June 29, 2022

Comments

  • Josiah
    Josiah almost 2 years

    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?