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
Solved

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

Posted on 2014-11-23
8
262 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 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 5

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 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

856 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