Send a Robocopy Job notification via Powershell

# Change these values
$Logfile = “C:\Scripts\Logs\AffSql_” + (Get-Date).tostring(“yyyyMMdd”) + “.log”
 
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
 
# Copy Folder with Robocopy
$command = 'Robocopy.exe "\\unc\path\" "E:\localpath" /S /MIR /R:10 /W:5 /LOG+:$Logfile /NP /TS /FP /COPY:DAT'
iex $command
 
# Send E-mail message with log file attachment
$smtpServer = "smtpserver"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "from@domain.com"
$msg.To.Add("to@domain.com")
$msg.Subject = "SQL Backup"
$msg.Body = get-content $Logfile | out-string
$smtp.Send($msg)
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Send a Robocopy Job notification via Powershell, 10.0 out of 10 based on 1 rating

Tags: alert, email, powershell, robocopy, smtp

Trackback from your site.