Advertisement
dantpro

Purge Old IIS Log Files

Jan 27th, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Purge Old IIS Log Files
  2. #
  3. # http://goo.gl/CrcSH7
  4.  
  5. Param (
  6.     # Files History Depth in Days
  7.     [int]$Period = 10 ,
  8.    
  9.     # Purge this catalog
  10.     [String]$PATH = "C:\inetpub\logs\LogFiles" ,
  11.    
  12.     # Include subdirectories
  13.     [bool]$recurse = $true
  14.     )
  15.    
  16. filter Get-OldFiles
  17. {
  18.     if    
  19.        (($_.Attributes -ne "Directory") `
  20.             -and `
  21.             (([DateTime]::Now.Subtract($_.CreationTime)).Days -gt $Period))
  22.         {return $_ }
  23. }
  24.  
  25. if ($recurse)
  26.         {dir -path $PATH -recurse  | Get-OldFiles -Period $Period | Remove-Item -recurse -force}
  27. else
  28.         {dir -path $PATH | Get-OldFiles -Period $Period | Remove-Item -force}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement