This is a simple PowerShell script to recursively delete all files that are older than 7 days in a specific directory:
$TargetFolder = “D:\Company\DropBox”
foreach ($i in Get-ChildItem $TargetFolder -recurse)
{
if ($i.CreationTime -lt ($(Get-Date).AddDays(-7)))
{
Remove-Item $File.FullName -force
}
}
And if you only want to include specific extensions, let’s say for example .html and .txt, a little addition to the script is required:
$TargetFolder = “D:\Company\DropBox”
foreach ($i in Get-ChildItem $TargetFolder -recurse -include *.txt, *.html)
{
if ($i.CreationTime -lt ($(Get-Date).AddDays(-7)))
{
Remove-Item $File.FullName -force
}
}

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 