3

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.

2 Answers 2

3

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
1
  • 1
    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, 2014 at 19:05
0
Import-Module WebAdministration
(gi IIS:\Sites\$webSite).logfile.directory
1
  • 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, 2015 at 22:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .