PowerTip: Use PowerShell to Copy Items and Retain Folder Structure

PowerTip: Use PowerShell to Copy Items and Retain Folder Structure

  • Comments 4
  • Likes

Summary: Copy items in a folder and retain the container with Windows PowerShell 3.0.

Hey, Scripting Guy! Question How can I use Windows PowerShell 3.0 to copy a folder structure from a drive to a network share, and retain the original structure?

Hey, Scripting Guy! Answer Use the Copy-Item cmdlet and specify the –Container switched parameter:

Copy-Item c:\fso –destination \\server1\share -recurse -container

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Cool. Had no idea this switch existed

  • Best is to do it not with PowerShell!

    There are more than one pitfalls! E.g. See Path too long exception  social.technet.microsoft.com/.../12179.net-powershell-path-too-long-exception-and-a-net-powershell-robocopy-clone.aspx

    You have to maintain the logging and the checksum stuff (Bit checking) by yourself!

    Best practice is to use approved tools like robocopy..exe for such tasks!

  • Why the need for -container?  Isn't that what -recurse was supposed to do?

  • Container is true by default, so using it doesn't make any difference.