Skip to content
Ask the community about this page

How to find files that have not been updated for some time?

The PowerShell Data Provider in Timextender Orchestration and Data Quality can be used for various things. In this post you will create a test, using PowerShell, to watch a directory and find all files that have not been modified for the past 31 days.

  1. Create a new Query in Timextender Orchestration and Data Quality by right-clicking the Data Quality > Tests folder
  2. In the query window add the following PowerShell script

# Check for files older than $Days in the folder $TargetFolder
$Days = "31" 
$TargetFolder = "C:\temp"

# Create the result DataTable
$timeXtenderResults= New-Object system.Data.DataTable

# Create column definition
$fileName = New-Object system.Data.DataColumn fileName,([string])
$timeXtenderResults.columns.add($fileName)
$modifiedDate = New-Object system.Data.DataColumn modifiedDate,([datetime])
$timeXtenderResults.columns.add($modifiedDate)

$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)

# Find the files
$Files = Get-ChildItem $TargetFolder | Where { $_.LastWriteTime -le $LastWrite } | sort-object LastWriteTime
foreach ($File in $Files)
{
    # Add Row
    $row = $timeXtenderResults.NewRow();
    $row.fileName = $file.name;
    $row.modifiedDate = $file.LastWriteTime;
    $timeXtenderResults.Rows.Add($row);
}
3. Change the $TargetFolder variable to your directory 4. Configure email settings and schedule as normal.

That’s it. Now you have a test that notifies you of all files that have not been modified for the past 31 days.

Discussed in the community

Looking for related questions…

Didn't find your answer? Ask the community about this page — questions are answered by Timextender experts, partners and other users.