Share this page : facebooktwitterlinkedinmailfacebooktwitterlinkedinmail

Powershell does not have a cmd-let to do this work, but we can create a new function to do this job:

Function Get-NeglectedFiles

{

 Param([string[]]$path,

       [int]$numberDays)

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

 Get-ChildItem -Path $path -Recurse | Where-Object {$_.LastAccessTime -le $cutOffDate}

}

Get-NeglectedFiles -path E:\data -numberDays 730 | % { Write-Host $_.FullName }

Function Get-NeglectedFiles will fist get two parameters: the path to search $path, how many days has the file not been accessed $numberDays.

Then we caculate the data since when the file has not been accessed: Get-Data.addDays(-$numberDays).

Get-childItem will search files in $path. -Recurse means also search subfolders. -le means files been accessed before the cutoffDate.

Then we call the Function Get-NeglectedFiles and pass two parameters to it, “% { Write-Host $_.FullName }” means show the full path of the file.

 

Problem

This may consume a lot of system resource if you search heaps of files. In my case, I tried to find all the old files older than 1 year in folder which is mapped as a network drive, then this resulted in some client machine stuck in opening the shared folder, some machine even can not load items in My computer because of the network drive.

Then I open the task manager, found the Windows Search consumed a lot of CPU and memory resource. After end the process, everything went back to normal.

 

Reference

Use PowerShell to Find Files that Have Not Been Accessed

http://stackoverflow.com/questions/13126175/get-full-path-of-the-files-in-powershell