Hi all,
Apologies if this sounds very dull but as a PowerShell newbie I am not sure how to search for answers on the web so thought i’d put it to the community here.
Basically, i have a script that i would like to run daily to check for backup results and output the results to the event log and to the PowerShell window.
I have it running presently and it gets the correct results and outputs them via ‘write-host’ correctly but when writing the data to the event log it will only read the first result and bypasses the others.
My code looks like the below…
New-EventLog -LogName Application -Source "VeeamResults" -ErrorAction SilentlyContinue > $null
Add-PSSnapin VeeamPSSnapin
$VbrJobs = Get-VBRJob | Sort-Object typetostring, name
Foreach($Job in $VbrJobs)
{
$JobName = $Job.Name
$Result = $Job.GetLastResult()
write-host $Job.Name finished with $Job.GetLastResult()
if($Job.GetLastResult() = "Success"){
Write-EventLog -logname Application -Source "VeeamResults" -EntryType Information -EventId 7777 -Message "All Veeam Jobs Succeeded"
}elseif($Job.GetLastResult() = "Warning") {
Write-EventLog -logname Application -Source "VeeamResults" -EntryType Warning -EventId 6666 -Message "Veeam Warnings Detected"
}elseif($Job.GetLastResult() = "Failed") {
Write-EventLog -logname Application -Source "VeeamResults" -EntryType Error -EventId 5555 -Message "Veeam Failures Detected"
}
}
The write-host output looks like this…
Backup to NAS finished with Success DC02 Replication to Host 3 finished with Success Replication to Host 3 finished with Warning
Apologies if its a bit of a mess, this is my first attempt with scripting.
If anyone can help me achieve the write-eventlog commands to look at each of the jobs and output accordingly i would be very grateful.
If anymore more information is needed from please please don’t hesitate to give me a nudge
Thanks in advance
Huw