Powershell-根据修改的时间同步文件

时间:2019-06-10 17:47:20

标签: powershell

我正在尝试基于修改后的时间在Powershell中进行单向同步,但是下面的代码似乎无法正常工作。有什么想法吗?

$Folder1Path = 'D:\test'
$Folder2Path = 'C:\test'


$Folder1Files = Get-ChildItem -Path $Folder1Path
$Folder2Files = Get-ChildItem -Path $Folder2Path

$FileDiffs = Compare-Object -ReferenceObject $Folder1Files -DifferenceObject $Folder2Files -Property modifyTimeStamp

$FileDiffs | foreach {
$copyParams = @{
                    'Path' = $_.InputObject.FullName
                    }
                if ($_.SideIndicator -eq '<=')
                {
                    $copyParams.Destination = $Folder2Path
                }

                Copy-Item @copyParams 
       }

0 个答案:

没有答案