So last week I had the great pleasure of sitting in on a two day training class provided by the great folks over at Midnight DBA. (t) The class was really informative. I have another blog post I’m working on which will dive into how great it was, but for the moment lets get back to my quest. I wanted to know which objects on my file server had not been accessed in 3 years. So I wrote the following script to give me that information.
1 2 3 4 5 6 |
#This script locates all objects older than 3 years. #To change the year value edit the $Date variable. -Values go back #in time. +Values are future dates. #The Out-File puts the results to a file called OldFile.txt $DATE = (Get-Date).AddYears(-3) Get-ChildItem C:\ -Recurse | Where-Object {$_.LastAccessTime -LT $DATE} | Out-File C:\Temp\OldFile.txt | FT -AutoSize |