This page looks best with JavaScript enabled

Log Manager Utility

 ·  β˜• 5 min read

Flexible clean up and backup of log files

For full change log and more information, visit my site.

Log Manager Utility is available from:

Please consider supporting my work:

  • Support with a one-time donation using PayPal.

Please report any problems via the ‘issues’ tab on GitHub.


Features and Requirements

  • The utility will delete files and folders older than X days.
  • It can also backup files and folders older than X days to another location.
  • It can also compress backups as a zip file.
  • The utility requires at least PowerShell 5.0
  • This utility has been tested on Windows 11, Windows 10, Windows Server 2022, Windows Server 2019, Windows Server 2016 and Windows Server 2012 R2.

Generating A Password File For SMTP Authentication

The password used for SMTP server authentication must be in an encrypted text file. To generate the password file, run the following command in PowerShell on the computer and logged in with the user that will be running the utility. When you run the command, you will be prompted for a username and password. Enter the username and password you want to use to authenticate to your SMTP server.

Please note: This is only required if you need to authenticate to the SMTP server when send the log via e-mail.

$creds = Get-Credential
$creds.Password | ConvertFrom-SecureString | Set-Content c:\scripts\ps-script-pwd.txt

After running the commands, you will have a text file containing the encrypted password. When configuring the -Pwd switch enter the path and file name of this file.


Here’s a list of all the command line switches and example configurations.

Command Line Switch Description Example
-LogsPath The path that contains the logs that the utility should process. [path]
-LogKeep Use this option to specify how long to keep logs for. Logs older than the number of days specified will be deleted. [number]
-BackupTo The path the logs should be backed up to. A folder will be created inside this location. If this option is not used, backup will not be performed. [path]
-BacKeep Use this option to specify how long to keep the backups. Backups older than the number of days specified will be deleted. [number]
-Wd Specify a ‘working directory’ for the creation of the zip file. [path]
-Compress This option will create a zip file of the log files. N/A
-Sz Configure the utility to use 7-Zip to compress the backups. 7-Zip must be installed in the default location $env:ProgramFiles if it is not found, Windows compression will be used. N/A
-ZipName Use this to name the zip file as you wish - the time and date will be appended to this name. “‘IIS Logs’”
-L The path to output the log file to. [path]
-LogRotate Remove logs produced by the utility older than X days [number]
-NoBanner Use this option to hide the ASCII art title in the console. N/A
-Help Display usage information. No arguments also displays help. N/A
-Subject Specify a subject line. If you leave this blank the default subject will be used “'[Server: Notification]'”
-SendTo The e-mail address the log should be sent to. For multiple address, separate with a comma. [[email protected]]
-From The e-mail address the log should be sent from. [[email protected]]
-Smtp The DNS name or IP address of the SMTP server. [smtp server address]
-Port The Port that should be used for the SMTP server. If none is specified then the default of 25 will be used. [port number]
-User The user account to authenticate to the SMTP server. [[email protected]]
-Pwd The txt file containing the encrypted password for SMTP authentication. [path\ps-script-pwd.txt]
-UseSsl Configures the utility to connect to the SMTP server using SSL. N/A


[path\]Log-Manager.ps1 -LogsPath [path\] -LogKeep [number] -BackupTo [path\]

This will backup and remove logs in the path specified older than X days.

Change Log

2022-06-14: Version 22.06.01

  • Added new feature: log can now be emailed to multiple addresses.
  • Added checks and balances to help with configuration as I’m very aware that the initial configuration can be troublesome. Running the utility manually is a lot more friendly and step-by-step now.
  • Added -Help to give usage instructions in the terminal. Running the script with no options will also trigger the -help switch.
  • Cleaned user entered paths so that trailing slashes no longer break things or have otherwise unintended results.
  • Added -LogRotate [days] to removed old logs created by the utility.
  • Streamlined config report so non configured options are not shown.
  • Added donation link to the ASCII banner.
  • Cleaned up code, removed unneeded log noise.

2021-12-09: Version 21.12.09

  • Moved config output so user can see it even if there’s no files to process.

2021-12-08: Version 21.12.08

  • Configured logs path now is created, if it does not exist.
  • Added OS version info.
  • Added Utility version info.
  • Added Hostname info.
  • Added an option to specify the Port for SMTP communication.
  • Changed a variable to prevent conflicts with future PowerShell versions.

2020-07-30: Version 20.07.27

  • Added improved error handling and reporting.

2020-07-21: Version 20.07.21

  • Fixed error when using script without a log output configured.

2020-03-23: Version 20.03.23

  • Fixed a user reported issue: wildcards in the -LogsPath switch no longer worked. They will now work.

2020-03-11: Version 20.03.11 ‘Cow’

  • The previous command line switch of -LogPath is now -LogsPath. This fixes an issue with a duplicate variable and switch alias preventing utility from running currently.

2020-03-09: Version 20.03.06 ‘Fish’

  • Added custom name for zip file based on user feedback.
  • Added option to use 7-zip for zip file backup.
  • Added time to keep backups for.
  • Added config report.
  • Added ASCII banner art when run in the console.
  • Added option to disable the ASCII banner art.
  • Refactored code.

2019-09-04 v1.8

  • Added custom subject line for e-mail.

2017-10-16 v1.7

  • Changed SMTP authentication to require an encrypted password file.
  • Added instructions on how to generate an encrypted password file.

2017-10-09 v1.6

  • Added necessary information to add the script to the PowerShell Gallery.

2017-09-20 v1.5

  • Improved log output to be more legible.

2017-06-21 v1.4

  • Improved commenting on the code for documentation purposes.
  • Added authentication and SSL options for e-mail notification.

2017-06-13 v1.3

  • First public release.
Share on
Support the author with