im trying to set up a Powershell script, which backs up a specific SiteCollection and sends an email afterwards, stating if the backup was successfully or not. I'm stuck at the point where I need to check if there was an exception or not. This is my code so far:
Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
try
{
$name = "xxxx"
$today = (Get-Date -Format dd-MM-yyyy)
[IO.Directory]::CreateDirectory("E:\Backup\SiteCollections\$name\$today")
Backup-SPsite -Identity http://xxxxxxx.xxxxx.de/sites/xxxxxx -Path E:\Backup\SiteCollections\$name\$today\$name.bak –Force
}
catch
{
#check for errors
}
#send mail success if no error
#send mail error if exception count is >0
At the end of the day my script should have checked whether an exception has occured or not and based on this alter the mail subject / body.
Any ideas on that?