Script to move file from one server to another server location

Is there good ps script to move files with extention *.bak from Server A  D:\Test Folder to \\ServerB\TestFolder

I want to run script as schedule task into windows to run every week and move

July 27th, 2015 11:51pm

Hi,

You can search the repository for prewritten scripts:

https://gallery.technet.microsoft.com/scriptcenter

If you want to try this yourself, you can take a look at Move-Item:

http://ss64.com/ps/move-item.html

You're likely better off just using robocopy for this though:

http://ss64.com/nt/robocopy.html

Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 11:59pm

Sample script. Try this.

$server1 = "C:\Users\Administrator\AppData\Local\Temp" ## enter current source folder
$server2 = "C:\Users\Administrator\AppData\Local\Temp\Target\" ## enter your destination folder 
foreach ($server1 in gci $server1 -include *.bak -recurse)
 { 
 Move-Item -path $server1.FullName -destination  $server2 ## Move the files to the destination folder
 }

July 28th, 2015 12:19am

thank you

Do I have to change the $server1 and $server2 with the right server names

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 1:25am

@MM - Yes, you need to change it to the correct UNC path.
July 28th, 2015 1:28am

I get an error message not sure if this is the right way to edit your sript

Source SERVER:     TEST03

Destination Server:   TEST01


$TEST03 = "E:\SQL Backups\Full\**.bak" ## enter current source folder
$TEST01 = "\\TEST01\d$\Full Backup\" ## enter your destination folder
foreach ($$TEST03 in gci $$TEST03 -include *.bak -recurse)
 {
 Move-Item -path $$TEST03.domain.local -destination  $TEST01.domain.local ## Move the files to the destination folder
 }

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 1:36am

$TEST03 = "E:\SQL Backups\Full" ## enter current source folder
 $TEST01 = "\\TEST01\d$\Full Backup\" ## enter your destination folder 
 foreach ($TEST03 in gci $TEST03 -include *.bak -recurse)
  { 
  Move-Item -path $TEST03 -destination  $TEST01 ## Move the files to the destination folder
  }
This will work. Give a try.
July 28th, 2015 2:13am

Move-Item : The file exists.
At C:\Scripts\Movefiles.ps1:5 char:3
+   Move-Item -path $********02 -destination  $*****01 ## Move the files to the ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (E:\SQL Backups\...008_6525.bak:FileInfo) [Move-Item], IOException
    + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 3:49am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics