Tuesday, 27 October 2015

Powershell Script to delete 90 days old SharePoint ULS logs


#---------------------------------------------------------------#
#Script Ttile : deleting the 90 days old log files from one server
# Scrit Author : KRR 
#---------------------------------------------------------------#

$SPLogs = "C:\logs"  # SharePoint log file location
$limit = (Get-Date).AddDays(-90)  #log file age
try
{
write-host "SharePoint ULS logs are deleting!!!!" -ForegroundColor Yellow -BackgroundColor Black

Get-ChildItem $SPLogs -Recurse |where-object{$_.CreationTime -lt $limit} | Remove-Item

write-host "SharePoint ULS logs deleted sucessfully" -ForegroundColor green -BackgroundColor Black
}
catch
{
write-error "error deleting the log files or no files found" 
}

#

1 comment:

  1. Script executing fine but not deleting files inside of the folder.

    Any idea why ?

    ReplyDelete