Change WinSCP PowerShell script to synchronize CSV files over 90 days old only

120 Views Asked by At

I would like to change this portion of a PowerShell script which uses WinSCP to connect to an SFTP Server.

I would like to modify this script so that in addition to downloading and then deleting .csv files but with the condition if they have a time stamp which is older than 90 days.

Any assistance is appreciated.

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "*.csv"

$synchronizationResult = $session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $False, $False,
    [WinSCP.SynchronizationCriteria]::Time, $transferOptions)
1

There are 1 best solutions below

1
Martin Prikryl On

Add a time constraint to the filemask:

$transferOptions.FileMask = "*.csv<90D"