Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
$name = "xxxx"
$today = (Get-Date -Format dd-MM-yyyy)

Backup-SPsite -Identity -Path     E:\Backup\SiteCollections\$name\$today\$name.bak –Force
 #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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Unless you change the ErrorVariable of PowerShell cmdlet they'll store error information in $Error

So you can just check $Error.Count to see if there is any errors

share|improve this answer
Sometimes I am just plain stupid. Thank you Per :> Works like a charm. –  Serv Oct 30 '12 at 13:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.