# ==============================================================================================
# NAME: SP2010_Farm_Backup_With_Notification.ps1
# AUTHOR: Juan Bautista Orrego
# DATE: 15 October 2014
# COMMENT: A Powerful Script to take backup of the entire SharePoint 2013 Farm with email notification.
# ==============================================================================================
Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
try
{
$today = (Get-Date -Format dd-MM-yyyy)
#Location of the Backup Folder
[IO.Directory]::CreateDirectory("\\SERVER\BackupSPFarm$\$today")
# This will actually initiate the SPFarm backup.
Backup-SPFarm -Directory \\SERVER\BackupSPFarm$\$today -BackupMethod full
#Define Variables
$emailFrom = "AdmGral@.com"
$emailTo = "@"
$emailTo1 = "@"
$subject = "[] PMP - Backup Full SharePoint Exitoso"
$body = "La tarea PMP - Backup Full SharePoint Termino de manera exitosa para el dia: "+"$today Favor validar el log adjunto y documentar formato PMP, en caso de falla notificar al disponible."
$attachment = "\\SERVER\BackupSPFarm$\$today\spbr0000\spbackup.log"
$smtpServer = "0.0.0.0"
$message = new-object System.Net.Mail.MailMessage
$message.From = $emailFrom
$message.To.Add($emailTo)
$message.To.Add($emailTo1)
$message.IsBodyHtml = $True
$message.body = $body
$message.Subject = $subject
$message.Attachments.Add($attachment)
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)
}
Catch
{
#Define Variables
$ErrorMessage = $_.Exception.Message
$emailFrom = "AdmGral@"
$emailTo = "@"
$emailTo1 = "@"
$subject = "[] PMP - Backup Full SharePoint Fallido"
$body = "La tarea PMP - Backup Full SharePoint presento un error durante su ejecución para el: "+"$today Favor validar el log adjunto y documentar formato PMP, favor notificar al disponible. Mensaje de error: $ErrorMessage."
$attachment = "\\SERVER\BackupSPFarm$\$today\spbr0000\spbackup.log"
$smtpServer = "0.0.0.0"
$message = new-object System.Net.Mail.MailMessage
$message.From = $emailFrom
$message.To.Add($emailTo)
$message.To.Add($emailTo1)
$message.IsBodyHtml = $True
$message.body = $body
$message.Subject = $subject
$message.Attachments.Add($attachment)
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)
}
Comentarios