24.5 C
Dubai
Tuesday, December 6, 2022

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

Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Specialized in Microsoft Azure - Office 365 / Microsoft Exchange; conducted numerous projects worldwide in designing, supporting, and implementing messaging and virtualization infrastructure for medium-sized and large enterprises. Further, I am a Cloud Architect and Technical Advisor for various start-ups.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

× How can I help you?