Skip to content

Instantly share code, notes, and snippets.

View chrisreeves-'s full-sized avatar
💭
:(){ :|:& };:

Christopher Reeves chrisreeves-

💭
:(){ :|:& };:
View GitHub Profile
@DanAtkinson
DanAtkinson / GetFilesOlderThan30Mins.ps1
Last active May 27, 2021 05:45
Simple Powershell script to get files older than 30 minutes. Obviously adaptable as needed.
$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)})