Copy-Item does not preserve directory structure

by Jan 13, 2017


can someone please advise on the following

if I do

get-childitem -path C:SomeFolder -recurse | copy-item c:MyFolder

the files are copied flat into C:MyFolder  e.g. if I have a file under C:SomeFolderDir1MyFile.txt  it ends up in C:MyFolder as C:MyFolderMyFile.txt

I want the source path 'folders' to be created and the files placed in them accordingly (no matter how deep the folder structure goes)

I cannot see a parameter on copy-item to preserve folder structure from the source when copying

is there a way around this or is thing something Microsoft are going to add (I am using PowerShell 5.1)

Thank you