Topic "Retrieving the most recent file if, and only if, it was modified within the last hour"

Author Message
[View user's profile]

Joined: 2016-05-03
Posts: 4
Location: Richmond, VA, USA
I'm using a PowerShell script to retrieve a file from a remote directory. I only want to retrieve the most recent file if it was modified within the last hour. My code snippet is as follows:

$directoryInfo = $session.ListDirectory($remotePath)
$latest =
$directoryInfo.Files |
Where-Object { -Not $_.IsDirectory } |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1

I believe that I need to add another condition to the "Where-Object" clause, but I don't know the proper format. For example,

Where-Object { -Not $_.IsDirectory and <created/modified within the last hour> }

How do I do this? Is there a better way?

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24736
Location: Prague, Czechia
Your duplicate (and answered) question of Stack Overflow:

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License