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

前端 未结 5 1383
独厮守ぢ
独厮守ぢ 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:51

    If you want to mirror same content from source to destination, try following one.

    function CopyFilesToFolder ($fromFolder, $toFolder) {
        $childItems = Get-ChildItem $fromFolder
        $childItems | ForEach-Object {
             Copy-Item -Path $_.FullName -Destination $toFolder -Recurse -Force
        }
    }
    

    Test:

    CopyFilesToFolder "C:\temp\q" "c:\temp\w"
    

提交回复
热议问题