Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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"
$now=get-date
$daysOld=31

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

Thanks, These are 2008R2 machines.

share|improve this question
add comment

1 Answer

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 logfile.directory).Value
share|improve this answer
add comment

Your Answer

 
discard

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.