PowerShell Script to Roll log files.

This smal function takes a file and rolls it based on the logcount. Params are: Logfile  with the fulll path Filesize: this is how big the file must be for it to be rolled to the next file numberlogcount: this is the number of logs to save for the log file passed in. With the fol

4 Star
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • Think it doesn't work in newer versions of powershell
    1 Posts | Last post February 27, 2019
    • The for loop isn't counting the array right (it never rolls the first log), but if you change this line:
      for ($i = ($files.count); $i -gt 0; $i--) 
      to this:
      for ($i = (@($files).count); $i -gt 0; $i--) 
      it works. 
      Per: https://stackoverflow.com/questions/36574283/powershell-count-function-not-working-as-expected
  • Wildcard filenames and filesize null
    1 Posts | Last post September 19, 2018
    • Hi,
      1) Will %logfile take a wildcard or directory 
      2) Can -filesize be zero?
  • Not working if filename contains some digits
    1 Posts | Last post August 02, 2016
    • Hi Tom,
      Thanks you very much for the Reset-Log function.
      It saves me a lot of time.
      I faced a problem when the file name contains a digit.
      For example : myapp7function.log
      In that case, the Reset-Log function does not rotate after the myapp7function.log.7.
      ($_.name).trim($fn) returns Null for 'myapp7function.log.7' because '7' is removed by the trim function.
      I haved tried some changes.
      If '($_.name).trim($fn)'
      is replaced with 
      '($_.name)-Split("$fn.")' (all the occurences)
      Reset-Log works well even if the filename contains some digits.