Wednesday, November 7, 2012

Delete Exchange IIS Logs script

Most of the time disk space issue is getting because of logs generated by IIS or transaction logs. If you take care this proactively you can reduce such kind of incidents like transport service stoped.This made me to think about automate the deleting old log files. So here i created Scheduled tasks in exchange servers to delete old logs which are older than 30 days or whichever you want.

In the scheduled task action you just need to mention start program commands like below.


forfiles.exe /P C:\inetpub\logs\logfiles /S /M u_ex*.log /D -30 /C "cmd /c del @file"


Above command will delete iis logs older than 30days from inetpub log files folder. Same way you can create the command for deleting the transaction logs by changing the log path and filename.

If you have N number of servers in your organization it is difficult to create scheduled task manually with these settings. So you can create the scheduled task in one server and export it as XML file. Then run the below command from PowerShell with appropriate server name. It will create scheduled tasks remotely on all servers.


schtasks.exe /create /s Exch1/xml d:\dumps\Delete-OLDLogs.xml /tn Delete-OLDLogs


Here Delete-OLDLogs.xml is the exported XML file

Exch1 is the server name.

No comments:

Post a Comment