PowerShell to List Top X Most Recently Changed Files

Sometimes, you just want to know what programs or source code was most recently changed.

The excludes below were set up to work with BizTalk source directories. I was only wanting to see files changed by a person, so change the -Exclude list as needed.


cls
$sourceCodeDirectory = "D:\Source"
$numberOfFilesToRetrieve = 50 
$latestFiles = (Get-ChildItem -Path $sourceCodeDirectory -Attributes !Directory `
     -Recurse -Exclude *.dll, *.pdb, *.cache, File*.cs, *.xsd.cs, *.odx.ds, *.btp.cs, *.btm.cs, *.FileListAsolute.txt, *.btproj.user,
                       *.exe `
     | Sort-Object -Descending -Property LastWriteTime | select -First $numberOfFilesToRetrieve)
$counter =  0
foreach ($file in $latestFiles)
{
    if ($file.Fullname -notmatch "\\obj\\" -and $file.Fullname -notmatch "\\bin\\" )
       {
            $counter +=  1
            Write-Host $counter $file.FullName  $file.LastWriteTime
       }
}

Leave a Reply