script that generates email – doesnt work

Home Forums Scripting PowerShell script that generates email – doesnt work

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    tlewis0123
    Member
    #164408

    Good morning All!
    I have a script to run a daily backup. It is scheduled on the scheduler and is meant to generate an email upon completion. I know the syntax is correct because when I run it in debug mode the email gets generated properly. I feel like it might be a permissions issue and have tried with different credentials.

    Perhaps, I haven’t used the right combination of creds – I’m only human…but what I would really like is the ability to get some logging that will tell me what the issue/error is.

    Here is a snippet of the code:
    if ($bkerror -eq $null)
    {
    # success
    $summary = get-wbsummary
    [string] $emailline1 = “Last backup Time: ” + [string]$summary.LastSuccessfulBackupTime
    [string] $emailline2 = “Last backup destination: ” + [string]$summary.LastSuccessfulBackupTargetPath
    [string] $emailline3 = “Last backup drives: ” + [string]$Volume
    [string]$emailbody = $emailline1 + $emailline2 + $emailline3

    $scriptname = $myinvocation.mycommand

    $emailsubj = $computer + ” ” + $scriptname + ” ” + $dayofweek

    send-mailmessage -to “[email protected]” -from “[email protected]” -subject $emailsubj -smtpserver webmail.taxva.com -Body $emailbody
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.