Solved

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

Posted on 2014-11-23
8
253 Views
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.


Details
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.
0
Comment
Question by:MacGyver80
  • 3
  • 3
8 Comments
 
LVL 69

Accepted Solution

by:
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.
0
 
LVL 18

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, '\', $srcfile.name -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

0
 
LVL 3

Author Comment

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

Sorry
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 3

Author Comment

by:MacGyver80
ID: 40461178
Also, getting a "access Denied" on the transfers.
0
 
LVL 69

Expert Comment

by:Qlemo
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?
0
 
LVL 3

Author Closing Comment

by:MacGyver80
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!
0
 
LVL 69

Expert Comment

by:Qlemo
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

773 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