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


For example

IIS log directory for Client1




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 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

Adding [EXTERNAL] for emails with Auto Remove on Reply

In the world of spam and the number of phishing emails is increasing day by …

Leave a Reply

Your email address will not be published.