Avatar of MacGyver80
MacGyver80
Flag for United States of America asked on

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

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.
Scripting LanguagesShell ScriptingPowershell

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Raheman M. Abdul

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

MacGyver80

ASKER
Thanks Olemo. Forgot to mention that I need a log output as well.

Sorry
MacGyver80

ASKER
Also, getting a "access Denied" on the transfers.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Qlemo

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

ASKER
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!
Qlemo

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.