Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Copy folder structure using powershell script

$
0
0

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

Lets say, there are folders mentioned below:

Main Folder: File aaa, File bbb

Sub Folder a: File 1, File 2, File 3

Sub Folder b: File 4, File 5, File 6

Script used:

Get-ChildItem -Path \\Server1\Test -recurse | ForEach-Object {
Copy-Item -LiteralPath $_.FullName -Destination \\server2\test |
Get-Acl -Path $_.FullName | Set-Acl -Path "server2\test\$(Split-Path -Path $_.FullName -Leaf)"

}

Output:
File aaa, File bbb

Sub Folder a (Empty Folder)

Sub Folder b (Empty Folder)

File 1, File 2, File 3, File 4, File 5, File 6.

I want the files to get copied to their respective folders (Like the source folders). Any further help is highly appreciated.

 

 


Viewing all articles
Browse latest Browse all 8411

Trending Articles