PowerShell script to get files that are no longer accessed

Subscribe to my newsletter and never miss my upcoming articles

I needed to produce a report for a client that showed all the files on their server that have not been accessed in a couple years.

There are bunch of third party tools but I wanted to incorporate PowerShell as it's built into Windows.

Here is the script I used to produce a csv file for review-

Function Get-NeglectedFiles




$cutOffDate = (Get-Date).AddDays(-$numberDays)

Get-ChildItem -Path $path -recurse |

Where-Object {$\_.LastAccessTime -le $cutOffDate}

Get-NeglectedFiles -path d:\\data\\folder1 -numberDays 730 | select name, LastWriteTime, CreationTime, Attributes, directory, DirectoryName, LastAccessTime, length| Export-Csv -Path C:\\temp\\oldfiles.csv -Encoding ascii -NoTypeInformation

No Comments Yet