Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell比较文件夹并将增量内容写入第三个文件夹_Powershell - Fatal编程技术网

使用PowerShell比较文件夹并将增量内容写入第三个文件夹

使用PowerShell比较文件夹并将增量内容写入第三个文件夹,powershell,Powershell,嗨,这里又是一个与PowerShell搏斗的新手 我有两个需要相互比较的数据文件夹:DirA和DirB。对DirA添加/删除文件夹或数据所做的所有更改都应复制到文件夹增量中。文件夹Delta将内容复制到DirB。我需要这样做才能在DirB所在的断开连接的网络中上传数据。我的问题是,数据似乎没有可靠地复制到Delta以及从Delta复制到DirB。必须同步的数据是几GB 这是我的密码。任何帮助或朝着正确的方向前进都将不胜感激 PS:我在上看到了这个示例,但是当我运行代码时,我看到了许多运行时错误。

嗨,这里又是一个与PowerShell搏斗的新手

我有两个需要相互比较的数据文件夹:DirA和DirB。对DirA添加/删除文件夹或数据所做的所有更改都应复制到文件夹增量中。文件夹Delta将内容复制到DirB。我需要这样做才能在DirB所在的断开连接的网络中上传数据。我的问题是,数据似乎没有可靠地复制到Delta以及从Delta复制到DirB。必须同步的数据是几GB

这是我的密码。任何帮助或朝着正确的方向前进都将不胜感激

PS:我在上看到了这个示例,但是当我运行代码时,我看到了许多运行时错误。哪里出了问题,我就抓不住

<# This script is being used to track changes between DirA and DirB. Changes will be copied to Delta folder and from here copied backwards to DirB to be in sync with DirA. Delta folder will be copied to an USB drive to be connected in disconnected network
#>


$src  = Get-ChildItem -Path "C:\DirA\" -Recurse 
$dst  = Get-ChildItem -Path "D:\DirB" -Recurse

Do a compare of scr and dst and copy the changes to the folder D:\Delta Compare-Object -ReferenceObject $src -DifferenceObject $dst
-Property Name, Length  | Where-Object {$_.SideIndicator -eq "<="} | ForEach-Object {
        Copy-Item C:\DirA\$($_.name) -Destination "D:\Delta\WsusContent" -Recurse -force
        }       

Copy-Item D:\Delta\* D:\DirB\ -Recurse -Force

我知道这与powershell的管道概念背道而驰,但在构建复杂管道时,我将使用内部对象来确保每个阶段都达到我的预期效果


一旦它工作正常,您就可以转换回典型的管道化…

您能发布您得到的错误吗?有完整源代码的最终解决方案吗?