Copy-item Files in Folders and subfolders in the same directory structure of source server using PowerShell

前端 未结 5 1476
独厮守ぢ
独厮守ぢ 2021-02-05 02:20

I am struggling really hard to get this below script worked to copy the files in folders and sub folders in the proper structure (As the source server).

Lets say, there

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 02:35

    This can be done just using Copy-Item. No need to use Get-Childitem. I think you are just overthinking it.

    Copy-Item -Path C:\MyFolder -Destination \\Server\MyFolder -recurse -Force
    

    I just tested it and it worked for me.

    edit: included suggestion from the comments

    # Add wildcard to source folder to ensure consistent behavior
    Copy-Item -Path $sourceFolder\* -Destination $targetFolder -Recurse
    

提交回复
热议问题