web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / HACKDBA / Finding old objects with Po...

Finding old objects with PowerShell. My 1st script!

HACKDBA Profile Picture HACKDBA 165

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.

#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

 

 

 

 

Comments

*This post is locked for comments