Clear Exchange 2013/2016/2019 Log & ETL Files

This script contains information from other scripts and combined to give you a working PS1 file that will go and remove all the log files generated by Exchange 2013 and Exchange 2016 and now on Exchange Server 2019 which is not automatically truncated.You can schedule this using

 
 
 
 
 
4.3 Star
(80)
115,145 times
Add to favorites
Exchange
7/31/2018
E-mail Twitter del.icio.us Digg Facebook
  • Does it work for Exchange 2016?
    2 Posts | Last post January 15, 2020
    • The Sub-category says Exchange 2013 only.
      
      Can I use the script on Exchange 2016?
    • It works on Exchange 2016 -  see my updated version of this script https://gist.github.com/RippieUK/108a49239ae8572774af91b05cc8fafb
  • Updated and cleaned up the code - Tested on Exchange 2016
    1 Posts | Last post January 15, 2020
    • Big thanks to Edward (author) for this script, it was just what i needed. I did tidy up the script, fixed a tiny few things.
      I ran this on my own Exchange 2016 server too
      
      https://gist.github.com/RippieUK/108a49239ae8572774af91b05cc8fafb
  • script typo
    1 Posts | Last post October 09, 2019
    • In CleanLogs(AccessDeniedFix.ps1 file this line is commented out
      
          #   $Files = Get-ChildItem $TargetFolder
      
      function won't work as expected
  • IIS Logs Dont delete
    2 Posts | Last post August 10, 2019
    • you forgot to change the path in line 15 to $TargetFolder
    • hank you for your answers. 
      line 15 has the next code on $Files = Get-ChildItem "C:\Program Files\Microsoft\Exchange Server\V15\Logging\" -Recurse | Where-Object {$_.Name -like "*.log" -or $_.Name -like "*.blg" -or $_.Name -like "*.etl"} | where {$_.lastWriteTime -le "$lastwrite"} | Select-Object FullName
      
      do you mean i have to remove the whole code and replace it with 
      C:\Program Files\Microsoft\Exchange Server\V15\Logging\" with $TargetFolder
      
      Thank you
  • $Files comment
    2 Posts | Last post August 05, 2019
    • Not a question, but i think there's an issue with the script.  Looks like lines 14 and 15 are a problem.
      
      Line 14 shows $files is supposed to perform Get-ChildItem on $TargetFolder, but this is commented out.  Instead, the line below it is live and powershell performs Get-ChildItem on "C:\Program Files\Microsoft\Exchange Server\V15\Logging\" instead of whatever path $TargetFolder is referencing.
      
      This is why iis logs aren't being removed.  It hasn't been mentioned, but neither are the ETL logging paths.
    • I agree. 
      A script update will be good.
  • seems to work but doesnt remove any of the files
    1 Posts | Last post December 07, 2018
    • when commenting out silently-continue the problem becomes visible. 
      
      Remove-Item : Cannot remove item C:\Program Files\Microsoft\Exchange Server\V15\Logging\ItemAssistants\MSExchangeMailboxAssistants20181119-73.LOG: The process cannot 
      access the file 'C:\Program Files\Microsoft\Exchange Server\V15\Logging\ItemAssistants\MSExchangeMailboxAssistants20181119-73.LOG' because it is being used by 
      another process.
  • help
    3 Posts | Last post November 16, 2018
    • The script isn't deleting the IIS logs. Is there something I'm supposed to change in line 15?
    • I am seeing this lately too. Not sure why. I tried various file and folder settings and it just won't delete those files. Hopefully someone finds a fix for this soon.
    • Sorry, see Gad_z response from July 12. Update that line and it will work.
  • This will clear only Clear logs in C: drive
    2 Posts | Last post October 26, 2018
    • what will happen if I install exchange on D Drive? I changed the path to D: on script but not working. 
    • Ignore my question. I changed the path 
  • Cause for the "Access denied" Error
    1 Posts | Last post October 03, 2018
    • Hello!
      I have testet on Exchange 2013 CU21 on Server 2012R2, PS Version is 4.0.
      If you run the Script with the Parameter $days=0, it would produce the error cause.
      The actual BLG File in "C:\Program Files\Microsoft\Exchange Server\V15\Logging\Diagnostics\DailyPerformanceLogs\" is loosing it NTFS Permissions.
      Also the actual ETL File in "C:\Program Files\Microsoft\Exchange Server\V15\Bin\Search\Ceres\Diagnostics\ETLTraces"
      On an Exchange 2016 also the actual ETL Files in "C:\Program Files\Microsoft\Exchange Server\V15\Logging\Query"
      So i think the Parameter $days should never be zero!
  • Exchange Database Log files
    3 Posts | Last post October 03, 2018
    • Hi, 
      
      Should this delete the script delete the Mailbox database log files as well? If not can this also be implemented (E0000000XXX.LOG and *.jrs files)? 
    • You dont want to do that, it will break your database. If you do not have a backup to truncate the logs, then you can enable circular logging on the database.
    • @Sunny_G Sorry, but this are ground basics, i think you should keep your hands off from exchange server!
1 - 10 of 46 Items