Powershell 搜索最新文件夹,然后从该文件夹上载最新文件

Powershell 搜索最新文件夹,然后从该文件夹上载最新文件,powershell,winscp,Powershell,Winscp,我要搜索最新文件夹,然后从该文件夹复制最新文件。我知道如何在文件夹中搜索最新的文件,但我一直坚持在文件夹中查找最新的文件夹 我正在尝试使用WinSCP脚本将文件传输到FTP位置。以下是我的脚本: option batch abort option confirm off open sftp://XYZ:ABC@123/ -hostkey="ssh-rsa w w w w w w w w w w" put -latest C:\A\B\2017\* "/ " exit 要在PowerShell

我要搜索最新文件夹,然后从该文件夹复制最新文件。我知道如何在文件夹中搜索最新的文件,但我一直坚持在文件夹中查找最新的文件夹

我正在尝试使用WinSCP脚本将文件传输到FTP位置。以下是我的脚本:

option batch abort
option confirm off
open sftp://XYZ:ABC@123/ -hostkey="ssh-rsa w w w w w w w w w w"
put -latest C:\A\B\2017\*  "/ "
exit

要在PowerShell的最新文件夹中查找最新文件,可以执行以下操作:

$FirstFolder = `
    Get-ChildItem -Force `
    | Where-Object -Property PSIsContainer -EQ -Value $true `
    | Sort-Object -Property LastWriteTime -Descending `
    | Select-Object -First 1

$FirstItemPath = `
    Get-ChildItem -Path $FirstFolder -Force `
    | Where-Object -Property PSIsContainer -EQ -Value $false `
    | Sort-Object -Property LastWriteTime -Descending `
    | Select-Object -First 1 -ExpandProperty FullName

然后使用上载选定的文件。