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
Technology Tips and News
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
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:
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 }
thank you
Do I have to change the $server1 and $server2 with the right server names
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
}
$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.
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