send mail on script failure

Posted on 2012-08-23
Last Modified: 2012-10-19
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...
Question by:Minesh Shah
    LVL 51

    Expert Comment

    do you have a CLI mail command?
    LVL 26

    Assisted Solution

    LVL 10

    Author Comment

    by:Minesh Shah
    Hi Hoffmann,
    we use windows servers.
    LVL 51

    Accepted Solution

    # a simple web-search returned something like:

    $msg = New-Object
    $msg.from = "from@me"
    $msg.Subject = “Subject:”
    $msg.Body = " - - your message here - - "
    $smtp = New-Object
    $smtp.Host = "FQDN-SMTP-server"  
    LVL 10

    Author Closing Comment

    by:Minesh Shah

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
    This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
    This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now