Last active
October 14, 2015 01:18
-
-
Save kkamegawa/4285724 to your computer and use it in GitHub Desktop.
Remove IIS Log file for IIS 7.0/7.5/8.0 after 7 days.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import-module WebAdministration | |
$iisroot = 'IIS:\Sites\' | |
$sites = get-itemproperty $iisroot | |
foreach($site in $sites.children) { | |
foreach($webroot in $sites.Children.Keys) { | |
$WebSite = join-path $iisroot $webroot | |
$logpath = get-itemproperty $WebSite -name logfile.directory.value | |
if($logpath -ne $null) { | |
$logpath = [environment]::ExpandEnvironmentVariables($logpath) | |
$files = get-childitem $logpath -include "*.log" -recurse | |
foreach($file in $files) { | |
if($file.lastwritetime.adddays(7) -lt [Datetime]::Now) { | |
remove-item $file.fullname | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment