इस powershell स्क्रिप्ट 5 दिन, 10 घंटे, और 5 मिनट पुरानी फ़ाइलों को दिखा देंगे। आप एक .ps1
एक्सटेंशन वाली फ़ाइल के रूप में सहेज सकते हैं और फिर इसे चलाएँ:
# You may want to adjust these
$fullPath = "c:\path\to\your\files"
$numdays = 5
$numhours = 10
$nummins = 5
function ShowOldFiles($path, $days, $hours, $mins)
{
$files = @(get-childitem $path -include *.* -recurse | where {($_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$mins)) -and ($_.psIsContainer -eq $false)})
if ($files -ne $NULL)
{
for ($idx = 0; $idx -lt $files.Length; $idx++)
{
$file = $files[$idx]
write-host ("Old: " + $file.Name) -Fore Red
}
}
}
ShowOldFiles $fullPath $numdays $numhours $nummins
निम्नलिखित लाइन फ़ाइलें फिल्टर के बारे में थोड़ा और अधिक विस्तार है। यह कई पंक्तियों में विभाजित है (कानूनी powershell नहीं हो सकता है) ताकि मैं टिप्पणी नहीं शामिल हो सकते हैं:
$lastWrite = (get-item $fullPath).LastWriteTime
$timespan = new-timespan -days 5 -hours 10 -minutes 5
if (((get-date) - $lastWrite) -gt $timespan) {
# older
} else {
# newer
}
कारण यह काम करता है:
$files = @(
# gets all children at the path, recursing into sub-folders
get-childitem $path -include *.* -recurse |
where {
# compares the mod date on the file with the current date,
# subtracting your criteria (5 days, 10 hours, 5 min)
($_.LastWriteTime -lt (Get-Date).AddDays(-$days).AddHours(-$hours).AddMinutes(-$mins))
# only files (not folders)
-and ($_.psIsContainer -eq $false)
}
)
स्रोत
2013-05-17 16:42:39
-OlderThan स्विच PS2.0 में उपलब्ध नहीं है। यह सुनिश्चित नहीं है कि इसे कब पेश किया गया था, लेकिन यह निश्चित रूप से PS4.0 में उपलब्ध है। – Mike