• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Robocopies in a one powershell script?

How can I run these three command line robocopies in a one powershell script?

robocopy \\server1\folder1 \\server2\folder1 /copyall /e /xo /fft /w:1 /r:1 /sec /z  /MIR
robocopy \\server1\folder2 \\server2\folder2 /copyall /e /xo /fft /w:1 /r:1 /sec /z  /MIR
robocopy \\server1\folder3 \\server2\folder3 /copyall /e /xo /fft /w:1 /r:1 /sec /z /MIR
1 Solution
Yes you can... Simply add it as it is, it should work...
Copy your lines of code to a PSL file for example:

test.psl and then double click on this file,

Before doing above make sure your execution policy is not restricted:

In power shell woindow type:
Set-ExecutionPolicy RemoteSigned

If you see restricted then set execution policy to remote signed

PS C:\> Set-ExecutionPolicy RemoteSigned
@unknown_routine, it's not .PSL it's .ps1

test.psl and then double click on this file,
PowerShell will not execute the script when you double click it, it's a security feature/measure!

You may need to refer this article on 'Running Windows PowerShell Scripts'
QlemoBatchelor and DeveloperCommented:
Of course you can make it more smart:
In cmd.exe batches:
@echo off
for %%D in (folder1 folder2 folder3) do robocopy \\server1\%%D \\server2\%%D /copyall /e /xo /fft /w:1 /r:1 /sec /z  /MIR

Open in new window

and in PS similar:
'folder1', 'folder2', 'folder3' | % { robocopy \\server1\$_ \\server2\$_ /copyall /e /xo /fft /w:1 /r:1 /sec /z  /MIR }

Open in new window

Both gets more useful the more folders you need to process.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now