This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$fullPath = "D:\path\to\directory" | |
$numDays = 0 | |
$numHours = 0 | |
$numMins = 30 | |
function getOldFiles($path, $maxDays, $maxHours, $maxMins) { | |
$currDate = Get-Date | |
#Get all children in the path where the last write time is greater than 30 minutes. psIsContainer checks whether the object is a folder. | |
$oldFiles = @(Get-ChildItem $path -include *.* -recurse | where {($_.LastWriteTime -lt $currDate.AddDays(-$maxDays).AddHours(-$maxHours).AddMinutes(-$maxMins)) -and ($_.psIsContainer -eq $false)}) |