LogDeleteActions -DaysToKeep 7 -PathToDelete C:\PathToLogsToDelete -Delete -ScriptLog C:\temp\logdelete.log
-DaysToKeep Number of days worth of logs you wish to retain (the rest will be deleted if used with the “-Delete” switch
-PathToDelete Location of the log files that you wish to remove
-Delete Using this switch will tell the script to delete Logs, it will report what has been deleted. Excluding this will just Report what would be removed.
-IncSubDirs Sets the script to run against all subfolders including the top (parent) folder.
-ScriptLog Where to log what will be / has been removed from the system by the script. (MANDATORY PARAMETER)
Removes log (.log) files based on criterea specified with parameters. Logging what would/has been removed.
Example would be C:\temp\Logdelete.log
As standard, the script will only remove log files from the TopDirectoryOnly (excluding subfolders).
You can use the -IncSubDirs to search AllDirectories (inc sub folders)
You can run this as a shceduled task by using the details below
1. Copy Powershell Module out to machine
2. create task using the action below (you can choose what schedule you wish to run this on, but the action has to be exactly as below (with your parameter details)).
Program / Script: powershell
Argument: -Command “Import-Module -Name “C:\pathtomodule\Logdelete_ps.psm1″ ; logdeleteactions -daystokeep 7 -pathtodelete C:\temp -delete -IncSubDirs -ScriptLog C:\temp\logdelete.log”
This script is provided “AS IS” with no warranties not supported by the author.
Brett Harris (Bdhphoto.com, @photo_bdh)
V2.0 – Added the ability to do top level folder only or all directories (Subfolders too)
V2.1 – Minor bug fix (the script now stops with an error if no $ScriptLog is specified) – 31/03/2016
You can find the Executable version of this on the link here
Please feel free to Login and leave feedback below.
[ddownload id=”1863″ style=”button” text=”Download”]
Download Size: [ddownload_filesize id=”1863″]
Downloaded [ddownload_count id=”1863″] times