Need advice on my script for backup reporting - Can it be simplified, is there a better way?


i need test successful backups , created script. working, since don't work in powershell much, appreciate input , advice.

$smtpfrom = "email"
$smtpto = "email"
$smtpsubject
$smtpbody
$smtpserver = "smtp.live.com"
$smtpclient = new-object net.mail.smtpclient($smtpserver, 25)
$smtpclient.enablessl = $true
$smtpclient.credentials = new-object system.net.networkcredential("username","password")

$smtpsubjecttrue = "the backup has completed successfully"
$smtpbodytrue = "the backup has completed successfully"

$smtpsubjectfalse = "the backup has not completed in last 24 hours"
$smtpbodyfalse = "the backup has not completed in last 24 hours"


$event = get-winevent -filterhashtable @{logname='application'; id=2003 ; starttime=(get-date).date}  -maxevents 1;
if($event.count -gt 0) {$smtpbody=$smtpbodytrue;$smtpsubject=$smtpsubjecttrue} else {$smtpbody=$smtpbodyfalse;$smtpsubject=$smtpsubjectfalse}


$smtpclient.send($smtpfrom, $smtpto, $smtpsubject, $smtpbody)

hi,

thanks posting.

this script can backup report:

$yesterday = (get-date) - (new-timespan -day 5)   get-winevent -logname "microsoft-windows-backup" |  {$_.timecreated -ge $yesterday} |  format-table timecreated, id, providername, message -autosize -wrap > c:\backupreport\servername.txt


this script below can helpful send e-mail , attach event report:

send-mailmessage -from email@gmail.com -to email@email.com -subject subject -body "open attachment report" -smtpserver smtp.gmail.com -attachments c:\backupreport\servername.txt -credentials (new-object system.management.automation.pscredential("username",("password" | convertto-securestring))

we can download last 5 days worth of events , emails combining 2 above scripts.

i hope helps.


we trying better understand customer views on social support experience, participation in interview project appreciated if have time.
helping make community forums great place.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Azure MFA with Azure AD and RDS

Failed to setup initiator portal. Error status is given in the dump data.

Invalid pointer on gpresult /h gpreport.html