I want to copy a folder, complete with subdirectories, files and files within subdirectories, preserving the structure and create them in a new location that did not previously exist. This is my PowerShell code
Copy-Item c:\development\powershell\folderone\* c:\development\powershell\foldertwo -recurse -Container
Copy-Item c:\development\powershell\folderone\* c:\development\powershell\folderthree -recurse -Container
foldertwo
exists and is empty, folderthree
does not exist.
If I run the script, the structure is created correctly in foldertwo
, however folderthree
gets created, but contains only all the files from the entire substructure, all at the root folderthree
level. It has not recreated the subfolders within folderone
, just put all the files at the root level of folderthree
.
What have I done wrong?