send mail on script failure

Hi Friends,

I have a simple script which makes nw connection, copies files from source to destination & closes the connection.

net use \\destinationpath\IPC$ "passwod" /user:domain\username
robocopy "sourcepath" "\\destinationpath" /MIR /IS
net use \\destinationpath\IPC$ /delete

Idea is to get an email if the above script fails in execution, any advise please...
LVL 10
Minesh ShahSharePoint & all about itAsked:
Who is Participating?
 
ahoffmannConnect With a Mentor Commented:
# a simple web-search returned something like:

$msg = New-Object system.net.mail.mailmessage
$msg.from = "from@me"
$msg.To.add("to@you")
$msg.Subject = “Subject:”
$msg.Body = " - - your message here - - "
$smtp = New-Object system.net.mail.smtpClient
$smtp.Host = "FQDN-SMTP-server"  
$smtp.Send($msg)
0
 
ahoffmannCommented:
do you have a CLI mail command?
0
 
Minesh ShahSharePoint & all about itAuthor Commented:
Hi Hoffmann,
we use windows servers.
0
 
Minesh ShahSharePoint & all about itAuthor Commented:
ok
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.