0

After some googling, majority of posts online talking about the goods of PowerShell, and the environment going to use robocopy is Windows Server 2016. Thus, an original batch file with two command lines is to be converted to its PowerShell version.

  1. What are the things to be careful of in order to convert the batch version of robocopy to PowerShell version? Since PowerShell is quite new and from scratch. Is there any PowerShell version difference like ps ver1 ver2 ver3? Anything could be benefited if using PowerShell or enhanced?

  2. What is the /b mode for? Microsoft official site seems not providing the details well....

The batch command is like below:

//get the locale independent time

    FOR /F %%A IN ('WMIC OS GET LocalDateTime ^| FINDSTR \.') DO @SET D=%%A

//unluckily could not find details of /b backup option to find out what is /b mode working for?

    robocopy X:\dat Y:\dat /v /xo /xa:sh /xj /unicode /mov /b /r:1 /w:1 /LOG+:C:\log\%D:~0,4%%D:~4,2%%D:~6,2%.log /xd "$RECYCLE.BIN" "System Volume Information"
3
  • /b copies files in backup mode. You can find information on robocopy's switches by running robocopy /?. What do you mean by "powershell is [...] from scratch"?
    – Worthwelle
    Oct 5, 2018 at 15:40
  • convert the batch version of robocopy to PowerShell version Do you mean, "convert the batch file that runs RoboCopy into a PowerShell script that performs the same task the batch file did?", or something else? Oct 9, 2018 at 2:49
  • @TwistyImpersonator Yes, how will it looks like for the robocopy statement to be runnable in powershell compared to the above copied version from bat robocopy?
    – Ken
    Oct 15, 2018 at 3:31

1 Answer 1

2

PowerShell is not new. Its been around for more than 10 years and is now cross platform, Win / OSX/Linux.

Robocopy (robocopy.exe) is a stand alone executable, regardless of what script / shell language you use it from. You don't need a .bat, .cmd, .ps1 script to use it. You can use it directly.

PS has it's own copy (Copy-Item), and delete (Remove-Item) cmdlets, but robocopy is the go to thing in most cases.

You can continue to use robocopy as you do today, even in PS, though handling the switches and arguments are a bit different, depending on what you are doing in your script.

The PS command prompt / consolehost (powershell.exe) can be used to replace the DOS command prompt. You'll use it almost identically. However, If you use script development tools / editors, ISE (powershell_ise.exe), Visual Studio Code, Notepad++, etc. you need to change your batch file mindset.

See this discussion about PS and Robocopy with answers

How to get robocopy running in powershell?

1
  • May I ask how it looks like in powershell version? this is a bat version: robocopy X:\dat Y:\dat /v /xo /xa:sh /xj /unicode /mov /b /r:1 /w:1 /LOG+:C:\log\%D:~0,4%%D:~4,2%%D:~6,2%.log /xd "$RECYCLE.BIN" "System Volume Information"
    – Ken
    Oct 15, 2018 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .