Scritping - Using robocopy to replicate files to remote location on scheduled tasks and sending final log and status email

Here is the script to use robocopy to backup file from a server to another:

you must schedule this script and executing with:

powershell file.ps1

# PowerShell Robocopy script with e-mail notification

# Change these values
$SourceFolder = "D:\"
$DestinationFolder = "\\IP\destination\"
$Logfile = "C:\robocopy-PCBACKUP.log"
$EmailFrom = "RobocopyFileServer@domain.XXX"
$EmailTo = "destination@domain.XXX, destination@domain.XXX"
$EmailBody = "Robocopy completed successfully. See attached log file for details"
$EmailSubject = "Daily Robocopy Summary"
$SMTPServer = "xxx.yyy.www.ttt"
$SMTPPort = "25"

# Copy Folder with Robocopy
Robocopy $SourceFolder $DestinationFolder /b /e /sec /w:30 /r:2 /ipg:5 /log:$Logfile /ndl /np /xd  "d:\System Volume Information" d:\patch d:\path2

# Send E-mail message with log file attachment
$Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)

$Attachment = New-Object Net.Mail.Attachment($Logfile)
$Message.Attachments.Add($Attachment)

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort)
$SMTPClient.Send($Message)

# /MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
#      /B :: copy files in Backup mode.
/E :: copy subdirectories, including Empty ones.
# /W:n :: Wait time between retries: default is 30 seconds.
# /IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.
# /NDL :: No Directory List - don't log directory names.
# /NP :: No Progress - don't display percentage copied.
# /XD dirs [dirs]... :: eXclude Directories matching given names/paths.



<---------------- -------------------------="" articles="" blog="" other="" related="">
<-------->
<-------->

more Robocopy parameters and Examples

http://www.devadmin.it/2016/02/27/copia-di-una-cartella-mantenendo-i-permessi-ntfs/


Tips - How to migrate file server share and permissions


http://www.alessandromazzanti.com/2015/11/tips-how-to-migrate-file-server-share.html


Server - Salvare i nomi e permessi di condivisioni di rete che utilizzano Netbios


http://www.alessandromazzanti.com/2011/03/salvare-i-nomi-e-permessi-di.html


Scritping - Use robocopy to replicate file to remote location



http://www.alessandromazzanti.com/2014/01/scritping-use-robocopy-to-replicate.html


[update 2016.07.19]

To force remote pc robocopy to a shared folder you can reuse these syntaxes:

robocopy \\yyyyyyyyyyy\c$\Users\xxxxxxxx\Favorites \\yyyyyyyyyyy\BackupUsers$\LAPxxxxxxx\xxxxxxxx\Favorites  /mir /ipg:25 /w:10 /r:1 /XF "*.pst

robocopy \\yyyyyyyyyyy\c$\Users\xxxxxxxx\Documents \\zzzzzzzzzzzz\BackupUsers$\LAPxxxxxxx\xxxxxxxx\Documents  /mir /ipg:25 /w:10 /r:1 /XF "*.pst


robocopy \\yyyyyyyyyyy\c$\Users\xxxxxxxx\Desktop Desktop \\zzzzzzzzzzzz\BackupUsers$\LAPxxxxxxx\xxxxxxxx\Desktop   /mir /ipg:25 /w:10 /r:1 /XF "*.pst