We had a client who needed to delete their aged IIS log files without human intervention. To do this requires two steps:
In the example below we are deleting from C:\inetpub\logs\LogFiles\W3SVC1
that have not been modified for more than 90 days:
ForFiles /p C:\inetpub\logs\LogFiles\W3SVC1 /s /d -90 /c "cmd /c del @file"
Note that you may need to put single or double quotes around your path but as you can see we did not.
/P = the path
/S = include subfolders
/D = MODIFIED Date (i.e. not necessarily creation date)
-90 = take 90 days off the Modified Date to include it in this filter
You can obviously adjust this to fit your requirements.
We wanted to avoid having to create a new local or domain user to run this script under because it is just one more account to reset the password on and just one more increase in the attack surface area. So we decided to have it run any time ANYONE logs on to that server and there are a couple of small quirks to make this work:
CLICK TO EXPAND GRAPHICS
USERS
and click OK/p C:\inetpub\logs\LogFiles\W3SVC1 /s /d -90 /c "cmd /c del @file"
This website uses cookies.