Intro

A simple PowerShell script to do a windows backup and send an e-mail report.

Code

###########################
# author : shebangthedolphins.net
# version : 1.0
# date : 2017.08
# role : windows backup a local server to \\192.168.1.90\d$\ntbackup\ share and send an e-mail report
# other : Work only with PowerShellv2
# updates :
#       - 1.X (x/x/xxxx) :    

#get days name
$backupdate = Get-Date -Format ddd

#Function Mail
#Role : Send email with Subject in argument
Function Mail
 {
	param ([string]$emailbody, [string]$sujet)

        $encoding = [System.Text.Encoding]::UTF8
        Send-MailMessage -To destination@shebangthedolphins.net -Subject $sujet -From source@shebangthedolphins.net -smtpserver smtp.shebangthedolphins.net -Body $sujet -Encoding $encoding
 }

#create a destination folder
New-Item -ItemType directory -Name $backupdate -Path \\192.168.1.90\d$\ntbackup\SRV01\

#Backup command. It will save C and D disk to \\192.168.1.90\d$\ntbackup\SRV01\ share
wbadmin start backup -backuptarget:\\192.168.1.90\d$\ntbackup\SRV01\$backupdate -systemState -include:C:,D: -quiet

if ($LASTEXITCODE -eq '0')
{
    Mail "Backup OK" "[Windows Backup] SRV01 backup successed"
}
Else
{
    Mail "Backup KO" "[Windows Backup] SRV01 backup has failed"
}
Licence Creative Commons
This websitehttp://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :