Powershell 将最近的两个文件复制到目标

Powershell 将最近的两个文件复制到目标,powershell,Powershell,我在另一个线程中找到了这个脚本 $ChildFolders = @('A', 'B') for($i = 0; $i -lt $ChildFolders.Count; $i++){ $FolderPath = "D:\BackupSource\" + $ChildFolders[$i] $DestinationPath = "D:\BackupDestination\" + $ChildFolders[$i] gci -Path $FolderPath -File |

我在另一个线程中找到了这个脚本

$ChildFolders = @('A', 'B')

for($i = 0; $i -lt $ChildFolders.Count; $i++){
    $FolderPath = "D:\BackupSource\" + $ChildFolders[$i]
    $DestinationPath = "D:\BackupDestination\" + $ChildFolders[$i]

    gci -Path $FolderPath -File | Sort-Object -Property LastWriteTime -Descending | Select FullName -First 1 | %($_) { 
        $_.FullName
        Copy-Item $_.FullName -Destination $DestinationPath 
    }
}
我需要这段代码,不仅要将第一项复制到目的地,还要将第二项复制到目的地

因此,需要将最新的两个文件从folder1复制到folder2。有人能帮我吗?

请更新:

Select FullName -First 2

感谢您对系统管理员的有用评论,他时不时地尝试编写一点脚本。@fur_xL-我很抱歉,这确实是不必要的。删除评论