Solved

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

Posted on 2014-11-23
8
239 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 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Olemo. Forgot to mention that I need a log output as well.

Sorry
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Author Comment

by:MacGyver80
Comment Utility
Also, getting a "access Denied" on the transfers.
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Set OWA language and time zone in Exchange for individuals, all users or per database.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now