Skip to main content

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


Christian Hauggaard
Community Manager
Forum|alt.badge.img+5

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.

Did this topic help you find an answer to your question?

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings