How to re-run one line of a PowerShell cmdlet if it fails

Posted by pansal on Server Fault See other posts from Server Fault or by pansal
Published on 2012-04-07T05:33:59Z Indexed on 2012/04/07 11:35 UTC
Read the original article Hit count: 236

Filed under:

I wrote a PowerShell script which is supposed to send emails automatically, but sometimes the email won't send out due to a network issue.

Here is how I'm sending email:

$smtp_notification.Send($mail_notification)

Here are the error logs:

Exception calling "Send" with "1" argument(s): "Failure sending mail."
At line:1 char:24
+ $smtp_notification.Send <<<< ($mail_notification)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Is there anyway to re-run the sending line when I met this failure? Can anyone give me some suggestions please?

© Server Fault or respective owner

Related posts about powershell