• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TECHDIIP

  • Tech
  • Windows
  • Powershell
  • Scripts
  • News
  • Games

Robocopy command with examples in powershell

How to use Robocopy command parameters and usage in Powershell scripts has been explained in a detailed way with real-time examples in daily life.

Robocopy commands

This Robocopy command is used for copying the file on  Windows machines, it is a very powerful command, it copies files and directories from one location to another. This Robocopy command also gives on-screen a detailed report of the copy operation.  Please find simple examples of how it copies one directory to another directory with detailed information.

Robocopy command examples

Robocopy syntax and examples

Source E:\resumes and destination F:\eng

Robocopy E:\resumes F:\eng

This commands copies of the files which include hidden files and gives the time taken to copy these files.

Let’s discuss some switches it has got.

Robocopy switch for to copy subfolders  /S

Robocopy /S E:\resumes  F:\eng

Robocopy switch for to copy  empty folder  /E

Robocopy /S /E E:\resumes  F:\eng

Robocopy  Delete source files after copying to destination.

One can add /MOV switch to the command to delete files and /MOVE switch to delete both files and directories.

For moving and deleting files:

Robocopy /MOVE /S  /E  E:\resumes  F:\eng

Below example is for  deleting files and directories:

Robocopy /MOVE /S /E   E:\resumes  F:\eng

Robocopy Modify file attributes for the copied files over the destination.

It is possible if one wants to change attributes of the copied files using the robocopy command. This affects the attributes of the files in the new location, however, the files in the source location do not get any impact that’s the beauty of this command.

Using the below example we achieve this, all files from one directory to another directory and also set the hidden attribute for all the files you can execute with ‘Robocopy’  as the syntax follows.

Robocopy /S /E  /A+:H  E:\resumes  F:\eng

Robocopy Mirror copy a directory very powerful

There is a very powerful command available Robocopy /MIR switch creates a replica of the source folder in the specified destination folder

Robocopy /MIR sourceFolderpath destinationFolderpath

This Robocopy /MIR command deletes any extra files that are present in the destination and are not present in source, makes exact replica of source folder and content.

Set same ACL access permission on the destination folder

The switch Robocopy  ‘/sec’ copies all the file access permissions to the destination folder.

robocopy /sec sourceFolderpath destinationFolderpath

Please make sure you have tested these commands in lower environments before you use them in the production environment For deeper understanding and learning of this command please visit the Microsoft website.

Robocopy Switches and Use Cases

/SECCopy files with security (equivalent to /COPY:DATS).
/COPYALLCopy all file info (equivalent to /COPY:DATSOU).
/NOCOPYCopy no file info (useful with /PURGE).
/SECFIXFix file security on all files, even skipped files.
/TIMFIXFix file times on all files, even the skipped ones.
/PURGEDelete dest files/dirs that no longer exist in the source.
/MIRMirror a directory tree (equivalent to /E plus /PURGE).
/MOVMove files (delete from the source after copying).
/MOVEMove files and dirs (delete from the source after copying).
/A+:[RASHCNET]Add the given attributes to copied files.
SThis switch used to Copy subdirectories, but not the empty ones.
/EThis switch used to Copy subdirectories, including the empty ones.
/LEV:nThis switch used to Only copy the top n levels of the source directory tree.
/ZThis switch used toCopy files in restartable mode.
/BThis switch used to Copy files in backup mode.
/ZBThis switch used for restartable mode. If access denied, use backup mode.
/EFSRAWThis switch used to Copy all encrypted files in EFS RAW mode.
/COPY:copyflag[s]This switch for What to COPY for files (default is /COPY:DAT).

 

Robocopy File Attributes

These below file attributes available when you deal with copy options.

    A – Archive

    C – Compressed

    N – Not content indexed

    H – Hidden

    E – Encrypted

    T – Temporary

    O – Offline

    R – Read only

    S – System

Robocopy File Logging Options

/L :  This parameter just lists the folders and files of destination path .

Robocopy command examples

/NP : This parameter  used for not to dissplay % copied.

/Unicode : This parameter  used for to Display the status output as Unicode text.

/LOG:file : This parameter  used for overwrite existing log.

/UNILOG:file : This parameter  used for Output status  Log file overwrite.

/LOG+:file : This parameter  used for appending information to existing log file.

/UNILOG+:file : Output status to Unicode Log file (append)

/NJH : This parameter  used for No Job Header information.

/NJS : This parameter  used setting No Job Summary after the execution.

/TS : This parameter  used  for Including Source file Time Stamps in the output.

/FP : This parameter  used  for Including full pathname of files.

/NS : This stands for No Size – This parameter  used for not to mention the log size.

/NC : This stands for No Class  and it is used don’t log file classes.

/NFL : This stands for No File List  and it is used don’t log file names.

/NDL : This stands for No Directory List and used as don’t log any directory names.

You May Also interested in reading…

1. Powershell-top 10 commands
2. 5-Best free Youtube video to audio converters
3. Top-5-Notepad-tricks-that-you-should-know-in-2021
4. Zoom-Testing

Thank you for reading this article, if you have any questions please let us know.

Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • How do Zoom Application Testing | Working or Not
  • Powershell script to test website status up or down on a local or remote computers
  • Solved: Server execution failed windows 10 Server 2016 and 2019
  • How to Fix windows 10 version 1903 error 0xc1900223
  • Free Music Making Software List One Can Try Out
  • About Us
  • CONTACT US
  • Disclaimer
  • Privacy Policy

Copyright © 2023 techdiip.com