daily pastebin goal
39%
SHARE
TWEET

Purge Old IIS Log Files

dantpro Jan 27th, 2015 238 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}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top