Have you ever needed to write some file, but the need for making sure the file size didn’t get out of hand made you have to write a ton of extra code? This is a very typical scenario when writing log files for instance. Out-File2 got you covered!
This function is a wrapper around Out-File, but adds the ability to automatically create backups of the file you are writing to if the file size is larger than what you specify. More over, you can specify how many backups you want to keep, and it will clean up the oldest files when that threshold is reached. You can choose between two different file suffixes; a counter and a date stamp.
You can customize the suffix separator, as well as the number of digits for the counter and the date format for the date suffix. Note that the default value for MaxFileSize is 0, which makes the function behave just like the regular Out-File cmdlet. If you want the advanced functionality you should set MaxFileSize to some value you are comfortable with, as well as use the Append switch.
This function is doing a lot of stuff, so please report any bugs to me (or fork the Gist and help me do it).
Oh! And if you come up with a better name than Out-File2, please let me know 🙂