dantpro icon

Purge Old IIS Log Files

dantpro | PRO | 01/27/15 08:58:52 AM UTC | 0 ⭐ | 601 👁️ | Never ⏰ | []
PowerShell |

670 B

|

None

|

0 👍

/

0 👎

# Purge Old IIS Log Files
#
# http://goo.gl/CrcSH7
 
Param (
    # Files History Depth in Days
    [int]$Period = 10 , 
    
    # Purge this catalog
    [String]$PATH = "C:\inetpub\logs\LogFiles" ,
    
    # Include subdirectories
    [bool]$recurse = $true
    )
    
filter Get-OldFiles
{
    if    
       (($_.Attributes -ne "Directory") `
            -and `
            (([DateTime]::Now.Subtract($_.CreationTime)).Days -gt $Period)) 
        {return $_ }
}
 
if ($recurse) 
        {dir -path $PATH -recurse  | Get-OldFiles -Period $Period | Remove-Item -recurse -force}
else
        {dir -path $PATH | Get-OldFiles -Period $Period | Remove-Item -force}

Comments