Ok so my goal is to create a script that will automate creating a snapshot of a server but will catch errors and send an email based off the error.
From what I can tell Try/Catch blocks will be the best way to accomplish this. This is what I have so far but I cant get it to catch the error.
Here is the snippet of the code
try
{
Get-VM $serverVMName | new-snapshot -Name "dppfr-$serverVMName-$TimeStr" -Description "Automated backup"
}
catch [system.exception]
{
sendError
}
Any thoughts?