Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am sure this is easy, but I can not find the answer. I am setting up a process to run a few tasks on the logging folder. Obviously I can manually create a variable with the log directory but this does change from machine to machine. I would like to be able to use some generic process.

What I have at the moment:

$iisLogDir = "D:\inetpub\Logs\LogFiles"

get-childitem $iisLogDir -recurse | where { !$_.PSIsContainer -and ($_.lastWriteTime -le $now.addDays(-$daysOld)) } | remove-item -whatif

Thanks, These are 2008R2 machines.

share|improve this question
up vote 3 down vote accepted

You can use the IIS WebAdministration Module and the Get-WebConfigurationProperty cmdlet.

Import-Module WebAdministration
(Get-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name
share|improve this answer
I have a site which has had the log directory moved to D:\ and this reports '%SystemDrive%\inetpub\logs\LogFiles. Am I correct in understanding that this is the default location, but a site may be in a different location and I need to find a different value? – flickerfly Nov 6 '14 at 19:05
Import-Module WebAdministration
(gi IIS:\Sites\$webSite)
share|improve this answer
It looks like you may have the knowledge to provide good Answer here, but please consider reading How do I write a good Answer? in our help center and then revise the Answer. Your Commands/Code may technically be the solution (I don't know) but some explanation is welcome. Also is that code valid for Windows 2008? Because AFAIK significant improvements have been in PS. Thanks in advance. – HBruijn Dec 23 '15 at 22:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.