How to find the oldest file in a certian location

I wanted to find the oldest recording on the local hardrive.

I had a Mitel call recorder (MIVCR) which had started deleting recording due to an error and i wanted to find out the oldest recording left on the recording drive

I could use the MIVCR software but that only shows you the oldest in SQL not the oldest on the hardrive (they maybe the same)

Same as everyone else i started by googling it. This is not my work. All credit goes to the original creator.

This is what i found and used. A Powershall script. I can not make that actual script file available but here is its contents.

$FileDate = (Get-Date -Format g)
$path = "R:\"
Get-ChildItem -Path $path -Recurse | ForEach-Object {
if ($_.LastWriteTime -lt $FileDate -and -not $_.PSIsContainer) {
$FileDate = $_.LastWriteTime
$OldFile = $_.FullName
Write-Host 'The oldest file on the system is: ' $OldFile

Just copy and paste it into Windows powershell ISE

Change the $path variable to the folder /drive you would like to search

This is the output you get

Leave a Reply

Your email address will not be published. Required fields are marked *