Search code examples
windowsfilepowershelltransferunc

How I can copy Data recursive from position A to position B with Powershell?


i want to create a powershell script that can copy data from position a to position b recursive.

this must do it with UNC-Paths.

On position b must all empty Orders delete.

I don't know how I can start :/


Solution

  • Both position A and position B need to be local paths or shares on the given server in this example.

    $a = '\\serverA\folderA'
    $b = '\\serverB\folderB'
    
    #This copies the files
    Get-ChildItem $a -Recurse -File | Foreach_Object {Copy-Item $_ -Destination $b}
    
    #Removes empty files
    Get-ChildItem $b -File | Foreach-Object {IF($_.Length -eq 0) {Remove-Item $_}}