From 6e7ec5e7458b57c409363c3f78b98adb14df8692 Mon Sep 17 00:00:00 2001 From: Matthew McKinnon Date: Sun, 2 Jun 2019 13:14:35 +1000 Subject: [PATCH] Added Powershell Script nasbakup.ps1 with Email Support --- nasbackup.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 nasbackup.ps1 diff --git a/nasbackup.ps1 b/nasbackup.ps1 new file mode 100755 index 0000000..c0ef192 --- /dev/null +++ b/nasbackup.ps1 @@ -0,0 +1,29 @@ +#Map Network Drive +New-PSDrive -Persist -Name "Z" -PSProvider "FileSystem" -Root "\\NAS\backup" -Confirm:$false + +# set variables +$date = get-Date -UFormat "%d-%m-%Y" +$SourceFolder = "D:\" +$DestinationFolder = "Z:\DATA" +$Logfile = "backup-$date.log" +$EmailParams = @{ + From = "support@comprofix.com" + To = "support@comprofix.com" + Subject = "Backup Log $date" + SMTPServer = "mail.comprofix.local" + Port = "25" +} + + +# copy +ROBOCOPY.EXE $SourceFolder $DestinationFolder /E /J /PURGE /MIR /X /FP /NS /NDL /ETA /TEE /np /LOG:$LogFile /XD "$RECYCLE.BIN" "System Volume Information" ".session" + + +# build email body +$EmailBody = (Get-Content $Logfile | % { "$_
" -replace "`t"," " -replace " "," " }) + +#send email +Send-MailMessage @EmailParams -Bodyashtml "
$EmailBody
" + +#Disconnect Network Drive +Get-PSDrive Z | Remove-PSDrive -Confirm:$false