Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 28, 2014 1:36 PM
Hello ,
How can I automate Sharepoint log deletion older than 5 months using powershell or C# code ?
All replies (3)
Wednesday, May 28, 2014 6:08 PM âś…Answered
you can get this by using the OOTB features of diagnostics logging. you can set the x number of days of retention( from 1-366 days), lets say if you select 150 days, then SharePoint automatically trim/delete the older logs.
Configure diagnostic logging (SharePoint Foundation 2010)
But if you have any intention then you can use the following script.even it is for IIS logs but still work.
http://spandps.com/2012/06/09/take-control-of-your-log-files/
Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog
Wednesday, May 28, 2014 2:13 PM
Hi
chedule the powershell script to run every 1. of month. An example how to split a log file:
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Split-large-log-6f2c4da0
For more details let me know
Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.
Wednesday, May 28, 2014 5:19 PM
I ran across this code (frankly forgot where) a few years ago, originally to delete IIS logs, but I use if for everything. It simply goes through each item in a folder and deletes by date. I save the code below to a ps script, then call it with a batch file and schedule a task to run the batch file (reasoning is it is easier to schedule a task to run as a .bat file than .ps1. Don't forget about changing the execution policy if you decide to use it on non-SharePoint servers as well.
get-childitem -Path C:\inetpub\logs\LogFiles -recurse |
where-object {$_.lastwritetime -lt (get-date).addDays(-7)} |
Foreach-Object { del $_.FullName }