WinBlogs

Some techy stuff and occasional verbose ramblings :D

IIS server, Windows and Powershell

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!

1 Comment

  1. David

    Great post! Thanks!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Theme by Anders Norén