Add these lines to scheduled tasks and run-as System:
Exchange logs older than 7 days:
1 |
gci ‘c:\program files\microsoft\exchange server\V15\Logging’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item |
IIS logs older than 7 days:
1 |
gci ‘C:\inetpub\logs’ -Directory | gci -Include ‘*.log’,’*.blg’ -Recurse | ? LastWriteTime -lt (Get-Date).AddDays(-7) | Remove-Item |
In Exchange 2013 this worked fine, but with Exchange 2016 You will get “Access Denied” for the folders.