PowerShell script to delete old IIS log files.
- IISLogsCleaner.ps1 - this is the worker script that task scheduler will run
- New-ScheduledScript.ps1 - this is the script to create a Scheduled Task (can be used to automate the process on multiple computers if PS Remoting is enabled)
- Login to server using RDP or local console
- Create restore point or snapshot if applicable (No snapshots on DC's or other data replication based servers such as Exchange/SQL/etc)
- Copy scripts to c:\scripts
- Open PowerShell
- Run script command
PS C:\Scripts> .\New-ScheduledScript.ps1 -ScriptFilePath C:\scripts\IISLogsCleaner.ps1 -LocalScriptFolderPath 'C:\' -TaskTriggerOptions @{'Daily' = $true; 'At' = '3Am'} -TaskName 'IISLogsCleaner' -TaskRunAsUser 'NT AUTHORITY\SYSTEM' -Computername localhost
- you can change -ComputerName to a remote computer if PowerShell Remoting is enabled on the server.
- RunAsUser is using SYSTEM account, no password is required as the system is running this locally. (Password variables were commented out of the script)
Adapted from: https://gallery.technet.microsoft.com/scriptcenter/Automatically-clean-up-old-8d35fdfd
Created by Robert.K and Kasha.K