On Exchange and other servers where you have IIS logfiles, the C drive or your log file location often fill up.
To prevent this from happening, its a good idea to create a scheduled task that runs daily checking your logfile folders for old files and delete these (unless you need them obviously.)
This script will create the job to remove your logfiles and create a scheduled task for you.
$user = ” ” #Add user you wish to run script as
$password= ” ” #add users password
$ScriptFolder = new-item -ItemType Directory -Path c:\scriptss\exchange -Force
#This creates ps1 file that we run in the scheduled job, with parameters on how we wish to delete files
New-Item -Path $ScriptFolder -Name Old-Logfiles.ps1 -ItemType File -Force
Add-Content -Path $scriptfolder\Old-Logfiles.ps1 -Value ‘$old = Get-ChildItem -Path “C:\inetpub\logs\LogFiles\” -Recurse -File | Where CreationTime -lt (Get-Date).AddDays(-15)’ -Force
Add-Content -Path $scriptfolder\Old-Logfiles.ps1 -Value ‘$old | remove-item -force’ -Force
Write-Host “File has been created in: $ScriptFolder”
#Create Scheduled Task
$action = New-ScheduledTaskAction -Execute ‘C:\Windows\system32\windowspowershell\v1.0\powershell.exe’ -argument “-command $scriptfolder\Old-Logfiles.ps1”
$trigger = New-ScheduledTaskTrigger -Daily -At 9am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName “Delete-Old-Logfiles” -Description “Deletes old Inetpub logfiles” -user $user -Password $password