PowerShell script that will move the SharePoint log files and set the retention of the log files.

To run this script you will need to set the PowerShell execution policy using the following PowerShell command:

set-executionpolicy Unrestricted

Copy the following code and paste it into a PowerShell script file like SetSPLog.ps1. To call this from the command line or within a command script file use the following syntax:

This will move the log files to D:\Logs\SharePoint, keeping 96 files that have 30 minutes of logs in each file.

powershell.exe "& .\SetSPLog.ps1 ‘D:\Logs\SharePoint’ 96 30"

PowerShell Code (SetSPLog.ps1)