Wednesday , October 23 2019

How to remove old files from specified directories using PowerShell-Plesk

Removing old iis logs in plesk

Here is the situation

I have 1600 + clients per server

And every client has its own IIS logs in their folder

image

For example

IIS log directory for Client1

“E:\Vhosts\Client1\Statistics\logs”

image

 

Wrote a Simple Script where it goes into these folders and removes the log files of every client which are 15 days old


$allclients = Get-ChildItem "E:\vhosts"

Foreach ($client in $allclients)

{
$location = "E:\vhosts\$client\statistics\logs\w3*"
$DeleteDays = (Get-Date).adddays(-4)
Get-ChildItem "$location" -Recurse | Where-object {$_.lastwritetime -lt $DeleteDays} | remove-item
}

Save it to .ps1 and run it Smile

Customize it as per your requirement

For plesk servers these are much suitable

About Satheshwaran Manoharan

Satheshwaran Manoharan is an Microsoft Office Server and Services MVP , Publisher of Azure365pro.com. Specialized in Office365 / Microsoft Exchange / Virtualization , Sathesh is an Messaging Expert supporting/Designing/Deploying many medium size businesses to large enterprises when it comes to Corporate messaging and Virtualization Infrastructure

Check Also

Save Public IPs using F5 LTM Policies

F5 has different modules and one of them is LTM – Local Traffic Manager . ...

Leave a Reply

Your email address will not be published.