Change log file location for all websites in IIS 7

Hi all 🙂

Today I had to change the location of all log files on all of the websites on the server. Since all sysadmins are lazy as hell, I wrote a simple powershell scripts that will do that.
All you need to do is change the path from “c:\logs” to some other .

Have phun! 🙂

Import-Module "WebAdministration" -ErrorAction Stop
foreach($site in (dir iis:\sites\*))
{
write-host $site.Name
#write-host $site.Bindings
#write-host $site.State
#write-host $site.physicalpath
Set-ItemProperty IIS:\Sites\$($site.Name) -name logFile.directory -value ‘C:\Logs’
}

If you uncomment these lines:

#write-host $site.Bindings
#write-host $site.State
#write-host $site.physicalpath

you can get additional information in your output.

But what if you want to have every log file in separate folder, and folder called by site name? Simple!


Import-Module "WebAdministration" -ErrorAction Stop
foreach($site in (dir iis:\sites\*))
{
write-host $site.Name
#write-host $site.Bindings
#write-host $site.State
#write-host $site.physicalpath

if (!(Test-Path -path C:\Logs\$($site.Name)))
{
New-Item c:\Logs\$($site.Name) -type directory
}
Set-ItemProperty IIS:\Sites\$($site.Name) -name logFile.directory -value “C:\Logs\$($site.name)”
}

This will create folder named the same as the websitename and set the log path to c:\logs\sitename\

So much for now.
Bye!

One thought on “Change log file location for all websites in IIS 7

Leave a Comment

Your email address will not be published. Required fields are marked *