Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-11-23
8
Medium Priority
?
332 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
7 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 1500 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 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, '\', $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 5

Author Comment

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

Sorry
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 5

Author Comment

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

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 5

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 71

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

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

772 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