Change the IIS Log File Directory via PowerShell

04/13/2010

PowerShell

One of the best things to do in your SharePoint environment is to relocate your log files to a central location. This gets them off of the C drive and easier to find during troubleshooting of issues. This change is pretty simple to do in PowerShell, but could cause an error and confusion if you overlook an important step.

Here is the command to change the log file directory:

Set-ItemProperty ‘IIS:\Sites\SharePoint – 80’ -name logFile.directory -value ‘C:\Logs\IIS’

Make sure to change “SharePoint – 80” to the name of the IIS site that you would like to change the log directory. Also, change the value parameter to the path that you have designated for your log file location. Note: I would not put the log files on the C drive – I just have it as the C drive since this is a small virtual machine I’m using.

Pop open the SharePoint 2010 Management Shell and enter the above command to change the log file directory: (Start > All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell)

Opps, we got an error! The error states that it cannot find the IIS drive. This tells us that the IIS snap-in has not been loaded. Let’s load that now using Import-Module WebAdministration.
Once you have imported the IIS snap-in, press the up arrow key and re-run the command to change the log directory:

Now, open up the IIS Manager console, expand Sites, click on the site you changed the log directory for and double click on Logging under the IIS section. You should see the new directory location under Log File.

Completed! If you have the schedule set to “Daily”, then you will not see a log file within the new path until the next day. Also, if you desire, you can manually move the old log files into this new location. Keep in mind that this log directory change will not replicate to other servers. So, you will need to perform this on each server.
_____________________

Sponsors *Trusted SharePoint Ads Only!*

Packaged Enterprise Search
for SharePoint.View a quick online demo here! Surfray.com/Ontolica

Free Outlook Sidebar!
Access SharePoint from Outlook w/ harmon.ie Sidebar. Download Now!

SharePoint Migration Tools
Sharegate: No-Brainer Migration Tools for SharePoint. $375.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.

8 Tips to Increase SharePoint Adoption
Download Free Whitepaper

Advertisements

Subscribe

Subscribe to our RSS feed and social profiles to receive updates.

8 Comments on “Change the IIS Log File Directory via PowerShell”

  1. ericstepek Says:

    Is there a way to change it universally at the Server level rather than at the individual site level?

    Reply

  2. Dongers Says:

    Also, have you found a way to to set and move the SP Logs using Powershell..?

    Want to set and move them to the D: drive on my servers, as part of my install script. Will save the manual configuration changes after the install…..

    ta

    Dongers

    Reply

  3. rachael Says:

    I moved my log files via IIS Manager, but web analytics reports are empty. I assume it’s because it web analytics service cannot find the logs.

    Does setting the properties via PowerShell take care help?

    Reply

  4. Andrzej Says:

    If you want to change log file location for all sites on IIS server in one step, here is a simple PS code:

    [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Web.Administration”)
    $iis = new-object Microsoft.Web.Administration.ServerManager
    $iis.SiteDefaults.LogFile.Directory = “C:\Logs\IIS\”
    $iis.CommitChanges()

    Reply

Trackbacks/Pingbacks

  1. SharePoint 2010/IIS Log Files – How to move them….. - Useful to me, anyway….. - Useful Stuff….IT Odds n Sods - 10/08/2010

    […] https://sptwentyten.wordpress.com/2010/04/13/change-the-iis-log-file-directory-via-powershell/ […]

  2. Anonymous - 09/27/2011

    Ok, Auto clicker is a small tool that help me well….

    […]Change the IIS Log File Directory via PowerShell « SP2010 Blog[…]…

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: