is there equivalent of rsync in MS powershell?

Rsync is very useful, I don't have to copy all files in a directory. It updates only the newer files.

I use it with cygwin but I think there are some inconsistencies, which are not the main focus of this question.

so is there an equivalent?

2 Answers

Although not an exact equivalent, and not a Powershell feature, robocopy can do some of the things rsync is used for.

See also

This works to synchronize directories between. Call the function "rsync ". i had permissions problems with robocopy. This doesn't have those issues.

function rsync ($source,$target) { $sourceFiles = Get-ChildItem -Path $source -Recurse $targetFiles = Get-ChildItem -Path $target -Recurse if ($debug -eq $true) { Write-Output "Source=$source, Target=$target" Write-Output "sourcefiles = $sourceFiles TargetFiles = $targetFiles" } <# 1=way sync, 2=2 way sync. #> $syncMode = 1 if ($sourceFiles -eq $null -or $targetFiles -eq $null) { Write-Host "Empty Directory encountered. Skipping file Copy." } else { $diff = Compare-Object -ReferenceObject $sourceFiles -DifferenceObject $targetFiles foreach ($f in $diff) { if ($f.SideIndicator -eq "<=") { $fullSourceObject = $f.InputObject.FullName $fullTargetObject = $f.InputObject.FullName.Replace($source,$target) Write-Host "Attempt to copy the following: " $fullSourceObject Copy-Item -Path $fullSourceObject -Destination $fullTargetObject } if ($f.SideIndicator -eq "=>" -and $syncMode -eq 2) { $fullSourceObject = $f.InputObject.FullName $fullTargetObject = $f.InputObject.FullName.Replace($target,$source) Write-Host "Attempt to copy the following: " $fullSourceObject Copy-Item -Path $fullSourceObject -Destination $fullTargetObject } } }
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like