Thursday, April 18, 2013

Delete file last modified day over 30 days by PowerShell

$TargetFolder = "X:\30days"
$Childitems = Get-Childitem $TargetFolder -recurse |where {$_.attributes -ne "Directory"}
$mdate = Get-Date -format yyyyMMdd
foreach ($i in $Childitems)
{
    if ($i.CreationTime -lt ($(Get-Date).AddDays(-30)))
    {
Write-host $i.fullname -- $mdate
        Remove-Item $i.FullName -force -recurse

    }
}

Print Friendly and PDF
Share/Bookmark

No comments:

Post a Comment