32.3 C
Dubai
Monday, May 29, 2023

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
Award-winning Technology Leader with a wealth of experience running large teams and diversified industry exposure in cloud computing. From shipping lines to rolling stocks.In-depth expertise in driving cloud adoption strategies and modernizing systems to cloud native. Specialized in Microsoft Cloud, DevOps, and Microsoft 365 Stack and conducted numerous successful projects worldwide. Also, Acting as a 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?