powershell - Script for Azure Backup notifications -


i's basic one, new powershell. trying statement below working.

$date = (get-date).adddays(-1)  $currentdate = get-date -format d  $check = get-winevent -filterhashtable @{logname="cloudbackup";starttime=$date;id=3} *>$null  if ($check -eq $true) {   write-host "`nok: azure backup successful on $currentdate"   exit 0 } else {   write-host "`ncritical: problem azure backup - $currentdate"   exit 2 } 

specially if ($check -eq $true) doesn't seem expected. $check checking event id 3 in eventlog, if it's there should return true, if not false. unfortunately it's returning false every time.

could please advise? there better way that?

$check = get-winevent ... *>$null 

your redirection suppressing all output, $check always has value $null, interpreted $false in boolean operation.

what want use automatic variable $? check if last powershell operation successful.

if ($?) {   write-host "ok: azure backup successful on $currentdate"   exit 0 } else {   write-host "critical: problem azure backup - $currentdate"   exit 2 } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -