Good day
Using this script you will be able to remove all the files in a folder tree that are older than 7 days
cls #Clear the Screen
Set-Location "Location Of the Folder" #Set the Folder Location
$alldir=ls #Get a list of files and store then in $alldir variable
$removebefore=date #get the current date and store it in $removebefore variable
$removebefore=$removebefore.AddDays(-7) # Before 7 Days
foreach($directory in $alldir){ #Prepare to read each item in the list
Get-ChildItem -Path $directory.PSChildName |where{$_.CreationTime -lt $removebefore} | Remove-Item
} #Read Each Item and show only the items with CreationTime is before $removebefore " the 7 days"
Hope its clear
if you have any command please write it down, and if you like this post please share it
No comments:
Post a Comment