Powershell | copy files from fileshare to NAS with no security or security information

Posted on 2014-11-23
Last Modified: 2014-12-09
Hey EE,

What would be the command for this? I would like for it to copy multiple folders with in a location without security information, permissions and it need to keep the timestamps as the source destination has.

Company A bought company B

Company B has a fileserver that company A would like transfered to new DC/FileServer on the same network on IPSec tunnel. Trying to use Robocopy to perform the transfer.
Question by:MacGyver80
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 70

Accepted Solution

Qlemo earned 500 total points
ID: 40461067
If you need to copy a single folder tree, only robocopy is needed:
robocopy \\srcserver\share \\dstserver\share /s /COPY:DAT

Open in new window

If you need to supply multiple folders, a batch file or PowerShell works (here shown for PowerShell as requested):
"folder1", "folder2", "folder3\subfolder" | % { robocopy \\srcserver\share\$_ \\dstserver\share\$_ /s /COPY:DAT }

Open in new window

/COPY:DAT is the default option, so we would not need to add that to the command. It says "copy attributes: data, attributes, timestamp". Security and owner info will not be maintained.
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 40461077
Try this:
$srcpath = 'D:\sourcePath'
$dstpath = 'D:\destinationPath'
$files = Get-ChildItem $srcpath

foreach ($srcfile in $files)
  # Build destination file path
  $dstfile = [io.FileInfo]($dstpath, '\', $ -join '')

  # Copy the file
  Copy-Item $srcfile.FullName $dstfile.FullName

  # Make sure file was copied and exists before copying over properties/attributes
  if ($dstfile.Exists) 
    $dstfile.CreationTime = $srcfile.CreationTime
    $dstfile.LastAccessTime = $srcfile.LastAccessTime
    $dstfile.LastWriteTime = $srcfile.LastWriteTime
    $dstfile.Attributes = $srcfile.Attributes

Open in new window


Author Comment

ID: 40461103
Thanks Olemo. Forgot to mention that I need a log output as well.

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Author Comment

ID: 40461178
Also, getting a "access Denied" on the transfers.
LVL 70

Expert Comment

ID: 40462950
RoboCopy has /LOG:filename or /LOG+:filename for logging into a text file.
Did you use a single-folder RoboCopy, or the PS script with multiple folders? Are you able to create the remote folder(s) manually?

Author Closing Comment

ID: 40489575
Thank you QLemo, you definitely led me int he right direction.  However, I didn't want security information or attributes so in the command, I had to omit /Copy:DATS to /Copy:DT.

Thanks again!
LVL 70

Expert Comment

ID: 40489608
I did not recommend DATS,  only DAT, and leaving out attributes was not part of the question. Based on the info I provided even that change was obvious. All in all no reason for a B grade.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question