<#====================================================================

Copyright © 2016, June. Michael Pomfret

Performs a Full or Differential backup of the local computer and emails user on completion.

1. Script set to complete a full backup on Sunday.

2. Script set to complete a Differential backup on every day excepy Sunday.

====================================================================#>

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

$ScriptStart = (Get-Date)

$strToday = “Universal Time: ” + $ScriptStart.ToUniversalTime()

$ThisComputer = $env:COMPUTERNAME

$backupDir = “<Drive>:\SharePoint\Backup\” + $ThisComputer

$strToday = (Get-Date).ToString(‘dd-MM-yyyy’)

if((get-date).DayofWeek -eq “Sunday”)

{

$subject = “Task Scheduler: Full Weekly Backup Scheduled for ” + $ThisComputer + ” ” + $strToday

$BackupType = “Full”

Backup-SPFarm -BackupMethod Full -Directory $backupDir

}

else

{

$subject = “Task Scheduler: Daily Backup Scheduled for ” + $ThisComputer + ” ” + $strToday

$BackupType = “Differential”

Backup-SPFarm -BackupMethod Differential -Directory $backupDir

}

$ScriptEnd = (Get-Date)

$RunTime = New-Timespan -Start $ScriptStart -End $ScriptEnd

$smtp = “courier.cf.ac.uk”

$to = “pomfretml@domain.com”

$from = “SharePoint@”+$ThisComputer+”.cf.ac.uk”

$body = “The ” + $BackupType + ” backup has completed for ” + $ThisComputer

$body += ” <br>”

$body += ” <br>”

$body += “Location of Backup ” + $backupDir

$body += ” <br>”

$body += ” <br>”

$body += “Time to complete: {0}:{1}:{2}” -f $RunTime.Hours,$Runtime.Minutes,$RunTime.Seconds

#### Now send the email using > Send-MailMessage

send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high