0

Hi again an rooky here struggling with PowerShell.

I have two folders of data which has to be compared with eachother: DirA and DirB. All the changes which are being made to DirA (adding/removing of folders-or data-) should be copied to the folder Delta. The folder Delta copies the content then to DirB. I need to do this to upload data in an disconnected network where DirB is residing. My problem is that the data does not seem to be copied reliably to Delta and from Delta to DirB. Data which has be to synced is several GB's

Here my code. Any help or move in the right direction is appreciated!

PS: I saw the example on Comparing folders and content with PowerShell but when I run my code I see many runtime errors. I can't geta hold on it where it goes wrong.

<# 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
Community
  • 1
  • 1

1 Answers1

0

I know it goes against the pipeline concept of powershell, but when building a complex pipeline, I'll use intramediary objects to make sure each stage does what I expect.

Once it works well,you can convert back to typical pipelining...

marceljg
  • 997
  • 4
  • 14