I also found the documentation less useful. I did some tests to see how the -Container works with -Recurse when copying files and folders.
Note that -Container means -Container: $true .
This is the file structure that I used for examples:
# X:. # ββββdestination # ββββsource # β source.1.txt # β source.2.txt # β # ββββsource.1 # source.1.1.txt
- For all examples, the current location (pwd) is
X:\ . - I used PowerShell 4.0.
1) To copy only the source folder (empty folder):
Copy-Item -Path source -Destination .\destination Copy-Item -Path source -Destination .\destination -Container
The following is the error:
Copy-Item -Path source -Destination .\destination -Container: $false
2) To copy the entire structure of folders with files:
Copy-Item -Path source -Destination .\destination -Recurse Copy-Item -Path source -Destination .\destination -Recurse -Container # X:. # ββββdestination # β ββββsource # β β source.1.txt # β β source.2.txt # β β # β ββββsource.1 # β source.1.1.txt # ββββsource (...)
3) To copy all descendants (files and folders) into one folder:
Copy-Item -Path source -Destination .\destination -Recurse -Container: $false
bouvierr Feb 15 '14 at 14:13 2014-02-15 14:13
source share