$chunk08 = $chunk06.Replace($chunk08,"<b>$chunk06</b><br>")
I think should be:
$chunk08 = $chunk08.Replace($chunk08,"<b>$chunk08</b><br>")


Nile Gilmanov
Systems Administrator
Wabash National Corporation
[email protected]<mailto:[email protected]> | O: 
765.772.2691 | M: 765.414.7402 | F: 765.449.5381

From: [email protected] [mailto:[email protected]] On 
Behalf Of Gilmanov, Nile
Sent: Friday, June 12, 2015 12:23 PM
To: [email protected]
Subject: [msmom] Daily Summary script

Just something I have been working on for a few hours, creates a summary of 
alerts(counts , group-by. I borrowed the skeleton elsewhere on the web and 
wrapped some stuff around it for HTML).

I intend to further filter by technology/class, there is potential there.

The cool thing I like is the subject, allows for some poor man's BI when sorted 
by date and subject in Outlook ha ha!

Criticism is welcome, as I could use ideas on how to improve this draft.

Code follows:

#Daily Alert Digest / Summary
Import-Module OperationsManager
New-SCOMManagementGroupConnection -ComputerName scom.yourCOMPANY.com

#
$AlertDateYesterdayBegin = [DateTime]::Today.AddDays(-1)
$AlertDateYesterdayEnd = [DateTime]::Today.AddDays(-1).AddSeconds(86399)

#get yesterdays alerts
$YesterdayAlerts = @(get-scomalert | where {$_.TimeRaised -gt 
$AlertDateYesterdayBegin -and $_.TimeRaised -lt $AlertDateYesterdayEnd})

#getting some numbers
$YAA = ($YesterdayAlerts).Count
$CAA = (get-scomalert | where {$_.ResolutionState -ne '255'}).count
$CAC = (get-scomalert | where {$_.ResolutionState -ne '255' -and $_.Severity 
-eq '2'}).count
$CAW = (get-scomalert | where {$_.ResolutionState -ne '255' -and $_.Severity 
-eq '1'}).count
$CAI = (get-scomalert | where {$_.ResolutionState -ne '255' -and $_.Severity 
-eq '0'}).count

$chunk01 = Write-output ("NUMBER OF ACTIVE ALERTS YESTERDAY: " + $YAA + "<br>")

$chunk02 = Write-Output ("CURRENT NUMBER OF ACTIVE ALL ALERTS: " + $CAA + 
"<br>")

$chunk03 = Write-Output ("CURRENT NUMBER OF ACTIVE CRITICAL ALERTS: " + $CAC)
$chunk03 = $chunk03.replace($chunk03,"<b style=color:red>$chunk03</b><br>")

$chunk04 = Write-Output ("CURRENT NUMBER OF ACTIVE WARNING ALERTS: " + $CAW)
$chunk04 = $chunk04.replace($chunk04,"<b 
style=color:darkorange>$chunk04</b><br>")

$chunk05 = Write-Output ("CURRENT NUMBER OF ACTIVE INFORMATIONAL ALERTS: " + 
$CAI)
$chunk05 = $chunk05.Replace($chunk05,"<b 
style=color:green>$chunk05</b><br><br><br>")

$chunk06 = Write-Output ("TOPLIST OF YESTERDAYS ALERTS SORTED BY COUNT:")
$chunk06 = $chunk06.Replace($chunk06,"<b>$chunk06</b>")

#list and sort yesterday alerts
$chunk07 = ($YesterdayAlerts | Group-Object Name |Sort -desc Count | 
select-Object Count, Name)


#list and sort current active alerts
$chunk08 =  write-output ("CURRENT ACTIVE CRITICAL ALERT LIST:")
$chunk08 = $chunk06.Replace($chunk08,"<b>$chunk06</b><br>")

$chunk09 = @(get-scomalert | where {$_.ResolutionState -ne '255' -and 
$_.Severity -eq '2'} | Group-Object Name | Sort -desc Count | select Count, 
Name)

$chunk07 = $chunk07 | ConvertTo-Html -Fragment #

$chunk09 = $chunk09 | ConvertTo-Html -Fragment #

$head = @'
<style>
body { background-color:#F2F5A9;
font-family:Verdana;
font-size:8pt; }
td, th { border: 1px solid green;
border-collapse:collapse; }
th { color:white;
text-align: left;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
</style>
'@
# make sure to update the path to HTML file you gen.
ConvertTo-HTML -Body "$chunk01 $chunk02 $chunk03 $chunk04 $chunk05 $chunk06 
$chunk07 $chunk08 $chunk09" -Title "SCOM Digest" -Head $head | Out-File 
c:\temp3\scom-digest.html

$subject = "Digest All: CAA $CAA" + " | " + "CAC $CAC" + " | " + "CAW $CAW" + " 
| " + "CAI $CAI"

# Send email as a HTML body.
$smtpServer = "gateway.YOURCOMPANY.com"
$MailFrom = "SCOM 
<[email protected]<mailto:[email protected]>>"
$mailto = 
"[email protected]<mailto:[email protected]>"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $MailFrom
$msg.IsBodyHTML = $true
$msg.To.Add($Mailto)
$msg.Subject = $subject
$MailTextT = Get-Content -Path C:\temp3\scom-digest.html
$msg.Body = $MailTextT
$smtp.Send($msg)
#testing piece
#Invoke-Item -Path c:\temp3\scom-digest.html




Reply via email to