Compress and Remove Log Files (IIS and others)

Archive Log Files: Manually specify any folder(s) or automatically parse IIS log folders, group by day/month and archive them with 7-Zip. Verify the archives and delete the original log files. Compressed archive will be about 4.5% (or less) of the size of the original log files.

4.8 Star
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Archive files only if older than n days
    2 Posts | Last post January 17, 2020
    • Is it possible to make this script only archive files that are older than a specified number of days/hours/etc.?
      For instance, we have a daily process that creates a report in a folder that is accessible to other users around our organization.  I would like to leave a few of the past reports in the folder, but archive report files that are more than 7 days old.
      I haven't found a way to do this so far, but maybe I have missed something...
    • You have to manage the code at line 309 of the script:
      $ArchiveDate = $CurrentDate.AddDays(-2).ToString("yyyyMMdd")
      change '-2' to your needs.
  • IIS log archive by hour
    2 Posts | Last post December 12, 2019
    • Hi,
      We are using this script to log our daily IIS archives and it works great.  Recently we were required to change to hourly IIS logs on our web servers.  What would it take for this script to support archiving by hour instead of manoth/day? The filename now contains the GMT hour (W3SVC1\u_ex19112219.log)...I tried manipulating $ArchiveGroupingString but I was not able to get it to work.  Any assistance would be appreciated.  Thanks.
    • As I can see the file name is not verified to manage which files where involved by $ArchiveGrouping.
      .LastWriteTime is checked instead.
      I think you have to add something like this 
      "hour" { 
              $ArchiveGroupingString = "{0:yyyy}{0:MM}{0:dd}{0:HH}" 
              $ArchiveDate = $CurrentDate.AddHours(-2).ToString("yyyyMMddHH") 
      and then setting
      $ArchiveGrouping = "hour" 
  • Thank you!
    1 Posts | Last post December 12, 2019
    • Thank you very much for your script.
      I edited it a bit for my needs.
      (file name equal to the log directory name and the ability to check if on an ID is present W3SCV and FTPSVC simultaneously)
  • Subfolder in the archive
    1 Posts | Last post May 03, 2019
    • For people interested in having files from subfolders in the same archive,
      change dir $TargetArchiveFolder | where {  
      to Get-ChildItem $TargetArchiveFolder -Recurse | where { 
      and $null = & $7z a -t7z -stl $PPMdSwitch $ArchiveFileName `@$ArchiveList 
      to $null = & $7z a -t7z -stl -spf2 $PPMdSwitch $ArchiveFileName `@$ArchiveList
      See here
  • No Files found to archive in IIS Locations
    2 Posts | Last post November 27, 2018
    • I have two websites on my server and when I run the powershell it always returns: 
      20181126: ------------------------------------------------------------------------------------------
      20181126: Info: No files found to archive in C:\inetpub\logs\LogFiles\W3SVC1
      20181126: ------------------------------------------------------------------------------------------
      20181126: Info: No files found to archive in C:\inetpub\logs\LogFiles\W3SVC3
      However, I have about 14 logs in each of the locations above and the script will not compress them. Any pointers?
    • Figured it out. I missed setting the ArchiveGrouping to "day"!
  • Error creating 7z file
    2 Posts | Last post June 29, 2018
    • Hi, nice script but on my W2k8R2 machine, with PShell v2 it just throws error in log without creating any zips? :
      There was an error creating the 7-Zip  
                          archive G:\wwwlogs-archive\Folder1\IIS-Logs-201805.7z
      Any ideas please?
    • Tried lots, then decided to NOT run directly from within PowerShell cmd prompt. Ran from regular dos prompt "powershell .\filename.ps1" that worked fine.
  • What am I doing wrong?
    2 Posts | Last post June 27, 2018
    • Hey,
      I'm using this to zip up backup files that look like this...
      I've got it archiving all the files, but using the Manual or ManualRecurse doesn't seem to do what I want and I'm hoping you can give me some suggestions.
      What I'd like is with all the files with the entire File Structure.
      What I seem to get is using the Manual or ManualRecurse is a zip that looks like this...
      Is there an easy way to zip the entire directory and keep the structure?
    • Well I found one reason for it...the manualrecurse option is grouping by day (or month) and my backup has files with many years of last written by, so it's creating hundreds of individual zip files.  Is there an easy way to remove the grouping so instead of doing it by day or month, it just zips files older than x?
  • move to github?
    1 Posts | Last post June 01, 2018
    • Hi Bernie,
      It is a nice script, but is there any chance it will be migrated to GitHub and made available for community support?
      For instance, I see there are few people who not really comfortable with using 7-Zip, and I am among them. I can change the script myself, but with GitHub such effort would also benefit the community.
  • Compress-Archive
    3 Posts | Last post May 17, 2018
    • Hi,
      A big thank you for creating this very useful and comprehensive script.
      For the environment I am working for we are not able/allowed to deploy 7zip.
      So I have added the following snippets to your script in order to remove the requirements for 7zip.
      Compression Method:
      elseif ($CompressionMethod -eq "Compress-Archive") { 
          $ArchiveExtension = ".zip" 
      Archiving the files:
      elseif ($CompressionMethod -eq "Compress-Archive") { 
                     Get-Content $ArchiveList | Compress-Archive -DestinationPath $ArchiveFileName 
      I'm not very experienced with PS but I managed to write the snippets above :)
    • Thomaspriv,
      Could you please provide the script after the changing the compression.
    • @Sjaina,
      Here you go:
      Please keep in mind that I am not experienced with PS and I probably broke some parts of the script.
      And ofcourse all credits go to Bernie.
  • Default compression Instead of 7zip
    1 Posts | Last post May 15, 2018
    • Script is really good with error handling. Could you please provide the same with windows default compression.
1 - 10 of 66 Items