Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SCOM 2012x Health Check HTML Report
  2. #Version 2.3
  3. #18-09-2015
  4. #Modified by Marnix Wolf:
  5. ##2.3 modifications:
  6. ###Added GW Server Primary & Failover MS server information
  7. ###Added warning when no Failover MS server for GW server is detected
  8. ###Added Generic Alerts Overview section
  9. ###Fixed issue where Unhealthy MMAs table didn't show in report
  10. ###Fixed issue where MMAs in MM table didn't show in report
  11. ###Fixed issue where MMAs in MM table missed Maintenance Mode Comments
  12. ###Added report section with SCOM license information
  13. ###Added detection and warning when only one SCOM MS server is present
  14. ###Modified report formatting for improved reading experience
  15. ##2.1 modifications:
  16. ###Added Generic Information section
  17. ###Added Top 10 Rule Based Closed Alerts section
  18. ###Added Top 10 Monitor Based Closed Alerts section
  19. ##2.0 modifications:
  20. ###Added Stopwatch for calculating total report creation time, displayed in last section 'Report Creation Time'
  21. ###Modified HTML Report file name, containing creation date and name of the MG
  22. ##1.9 modifications:
  23. ###Modified some report formatting and section titles
  24. ###Disabled the section which e-mails the HTML file
  25. #Resources:
  26. ## Jason Rydstrand for 2007 R2: http://blogs.technet.com/b/jasonrydstrand/archive/2013/03/27/daily-scom-health-check-with-powershell.aspx
  27. ## Scott Moss, updated to SCOM 2012x: https://gallery.technet.microsoft.com/scriptcenter/SCOM-2012-Daily-Health-5950d801
  28. ## Bob Cornelissen: SCOM Connection
  29. ## Tao Yang: Sanity Check
  30. ## PowerShell.com for Stopwatch class: http://powershell.com/cs/blogs/tips/archive/2014/04/09/logging-script-runtime.aspx
  31. #Additional Remarks:
  32. ## Update $UserName and $Password for your email server on Gmail
  33. ## Also update '$mailmessage.from' and '$mailmessage.To'. Add with who its coming from and going to
  34.  
  35. #Define Stopwatch and start it
  36. $StopWatch = [system.diagnostics.stopwatch]::startNew()
  37. $StopWatch.Start()
  38.  
  39. #Importing the SCOM PowerShell module
  40. Import-module OperationsManager
  41. #Connect to localhost when running on the management server
  42. $connect = New-SCOMManagementGroupConnection -ComputerName localhost
  43.  
  44. #Or enable the two lines below and of course enter the FQDN of the management server in the first line.
  45. #$MS = "enter.fqdn.name.here"
  46. #$connect = New-SCOMManagementGroupConnection “ComputerName $MS
  47.  
  48. #Define Report Date, used in filename of HTML Report
  49. $ReportDate = Get-Date -UFormat "%Y%m%d_"
  50. $ReportTime = Get-Date -Format "H-mm-ss"
  51.  
  52. #Get Date and Time in special formatting for HTML report
  53. $Date = Get-Date -UFormat "%A %d %B %Y"
  54. $Time = Get-Date -UFormat "%R"
  55.  
  56. # Create header for HTML Report
  57. $Head = "<style>"
  58. $Head +="BODY{background-color:#CCCCCC;font-family:Calibri; font-size: 12pt;}"
  59. $Head +="TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; width: 100%;}"
  60. $Head +="TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#0066ff;color:white;padding: 5px; font-weight: bold;text-align:left;}"
  61. $Head +="TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#F0F0F0; padding: 2px;}"
  62. $Head +="</style>"
  63.  
  64. #Define the customer name here. Modify the value for parameter $CustomerName
  65. $CompanyName = "ENTER COMPANY NAME HERE"
  66.  
  67. #Collect Generic information
  68. Write-Host "Collecting Generic Information" -ForegroundColor Gray
  69. ##Fill a bunch of variables
  70. $MGName = Get-SCOMManagementGroup | Select-Object -Expand Name
  71. $AmountGWs = (Get-SCOMManagementServer | where {$_.IsGateway -eq $true}).count
  72. $AmountMSs = (Get-SCOMManagementServer | where {$_.IsGateway -eq $false}).count
  73. $AmountMMAs = (Get-SCOMAgent).count
  74. #$SCOMLicenseProduct = Get-SCOMManagementGroup | ForEach-Object {$_.SkuForProduct}
  75. #$SCOMLicenseVersion = Get-SCOMManagementGroup | ForEach-Object {$_.Version}
  76. #$SCOMLicenseSKU = Get-SCOMManagementGroup | ForEach-Object {$_.SkuForLicense}
  77. #$SCOMLicenseExp = Get-SCOMManagementGroup | ForEach-Object {$_.TimeOfExpiration}
  78. $SCOMMG = Get-SCOMManagementGroup
  79. $SCOMLicenseProduct = $SCOMMG.SkuForProduct
  80. $SCOMLicenseVersion = $SCOMMG.Version
  81. $SCOMLicenseSKU = $SCOMMG.SkuForLicense
  82. $SCOMLicenseExp = $SCOMMG.TimeOfExpiration
  83. $SCOMLicensesLogicalCPU = Get-SCOMAccessLicense | measure-object -property LogicalProcessorCount -sum | ForEach-Object {$_.Sum}
  84. $SCOMLicensesPhysicalCPU = Get-SCOMAccessLicense | measure-object -property PhysicalProcessorCount -sum | ForEach-Object {$_.Sum}
  85. ##Pipe these variables into the report
  86. #When enabling the e-mail section of this PS script enable the next line (62) and add a '+' to line 63 so it becomes '$ReportOutput =+' instead of '$ReportOutput ='
  87. #$ReportOutput = "To enable HTML view, click on `"This message was converted to plain text.`" and select `"Display as HTML`""
  88. $ReportOutput = "<span style='color:#190707'>"
  89. $ReportOutput += "<p><H1>SCOM Health Check Report for Management Group: "
  90. $ReportOutput += "<span style='color:#0000FF'>"
  91. $ReportOutput += "$MGName</H1></p>"
  92. $ReportOutput += "<p><H2>Company: "
  93. $ReportOutput += "<span style='color:#0000FF'>"
  94. $ReportOutput += "$CompanyName</H2></p>"
  95. $ReportOutput += "<span style='color:#DF7401'>"
  96. $ReportOutput += "<p><H2>Generic Information</H2></p>"
  97. $ReportOutput += "<span style='color:#190707'>"
  98. $ReportOutput += "<p><H3><u>Report Information</H3></p></u>"
  99. $ReportOutput += "<ul>"
  100. $ReportOutput += "<li>Report File Name: "
  101. $ReportOutput += "<span style='color:#0000FF'>"
  102. $ReportOutput += "$ReportDate$ReportTime _SCOM Health Check Report MG $MGName.html.</li>"
  103. $ReportOutput += "<li>Report File Folder: "
  104. $ReportOutput += "<span style='color:#0000FF'>"
  105. $ReportOutput += "C:\Server Management.</li>"
  106. $ReportOutput += "<li>Creation Date & Time: "
  107. $ReportOutput += "<span style='color:#0000FF'>"
  108. $ReportOutput += "$Date, $Time hrs.</li>"
  109. $ReportOutput += "</ul>"
  110. $ReportOutput += "<p><H3><u>SCOM Infrastructure Overview</H3></p></u>"
  111. $ReportOutput += "<ul>"
  112. $ReportOutput += "<li>Management Group Name: "
  113. $ReportOutput += "<span style='color:#0000FF'>"
  114. $ReportOutput += "$MGName</li>"
  115. $ReportOutput += "<li>Total amount of SCOM Management Servers: "
  116. $ReportOutput += "<span style='color:#0000FF'>"
  117. $ReportOutput += "$AmountMSs</li>"
  118. $ReportOutput += "<li>Total amount of SCOM Gateway Servers: "
  119. $ReportOutput += "<span style='color:#0000FF'>"
  120. $ReportOutput += "$AmountGWs</li>"
  121. $ReportOutput += "<li>Total amount of Microsoft Monitoring Agents: "
  122. $ReportOutput += "<span style='color:#0000FF'>"
  123. $ReportOutput += "$AmountMMAs</li>"
  124. $ReportOutput += "</ul>"
  125. #Enumerate SCOM Management Servers
  126. $ManagementServers = Get-SCOMManagementServer | where {$_.IsGateway -eq $false} | Sort-Object DisplayName
  127. $ReportOutput += "<H3><u>SCOM Management Servers Overview</H3></u>"
  128. $ReportOutput += "<ol>"
  129. $ReportOutput += "<span style='color:#0000FF'>"
  130. foreach ($ManagementServer in $ManagementServers)
  131. {
  132. $ManagementServerName = $ManagementServer.DisplayName
  133. $ReportOutput += "<li>$ManagementServerName</li>"
  134. }
  135. $ReportOutput += "</ol>"
  136. #Throw warning when only ONE SCOM MS server is detected
  137. If ($AmountMSs -eq 1)
  138.     {
  139.     $ReportOutput += "<mark><span style='color:#FF0000'>!!!WARNING!!! Only ONE SCOM Management Server detected. This kind of setup is limited to labs ONLY, NOT for POC(s) and OTAP streets where TWO SCOM MS servers are the minimum requirement.</mark>"
  140.     $ReportOutput += "<span style='color:#190707'>"
  141.     }
  142. Else {}
  143. #Enumerate SCOM Gateway Servers
  144. if($AmountGWs -gt 0) {
  145.  $GatewayServers = Get-SCOMManagementServer | where {$_.IsGateway -eq $true} | Sort-Object DisplayName
  146.  $ReportOutput += "<H3><u>SCOM Gateway Servers Overview</H3></u>"
  147.  $ReportOutput += "<ol>"
  148.  $ReportOutput += "<span style='color:#0000FF'>"
  149.  foreach ($GatewayServer in $GatewayServers)
  150.  {
  151.  $GatewayServerName = $GatewayServer.DisplayName
  152.  $ReportOutput += "<li>$GatewayServerName"
  153.  $PrimaryMS = ($GatewayServer.GetPrimaryManagementServer()).ComputerName
  154.  $FailoverMS = ($GatewayServer.GetFailoverManagementServers()).ComputerName
  155.  If ($FailoverMS -eq $null) {
  156.  $FailoverMS = "<mark><span style='color:#FF0000'>None present. Please add a Failover MS Server for this Gateway Server!!!<span style='color:#190707'></mark>"
  157.  }
  158.  Else{}
  159.  $ReportOutput +="<span style='color:#190707'>. Primary MS: <span style='color:#0000FF'> $PrimaryMS. <span style='color:#190707'> Failover MS: <span style='color:#0000FF'> $FailoverMS</li>"
  160.  #$ReportOutput += "<span style='color:#190707'>"
  161.  }
  162.  $ReportOutput += "</ol>"
  163. }
  164. else {
  165.  $ReportOutput += "<H3><u>Gateway Servers</H3></u>"
  166.  $ReportOutput += "<p>No SCOM Gateway Servers found.</p>"
  167. }
  168. #SCOM License Information
  169. $ReportOutput += "<p><H3><u>System Center Licenses Overview</H3></p></u>"
  170. $ReportOutput += "<ul>"
  171. $ReportOutput += "<li>Licensed product: "
  172. $ReportOutput += "<span style='color:#0000FF'>"
  173. $ReportOutput += "$SCOMLicenseProduct</li>"
  174. $ReportOutput += "<li>License SKU: "
  175. $ReportOutput += "<span style='color:#0000FF'>"
  176. $ReportOutput += "$SCOMLicenseSKU</li>"
  177. $ReportOutput += "<li>License version: "
  178. $ReportOutput += "<span style='color:#0000FF'>"
  179. $ReportOutput += "$SCOMLicenseVersion</li>"
  180. $ReportOutput += "<li>License valid til: "
  181. $ReportOutput += "<span style='color:#0000FF'>"
  182. $ReportOutput += "$SCOMLicenseExp.</li>"
  183. $ReportOutput += "<li>SCOM Logical CPU licenses in use (sum): "
  184. $ReportOutput += "<span style='color:#0000FF'>"
  185. $ReportOutput += "$SCOMLicensesLogicalCPU</li>"
  186. $ReportOutput += "<li>SCOM Physical CPU licenses in use (sum): "
  187. $ReportOutput += "<span style='color:#0000FF'>"
  188. $ReportOutput += "$SCOMLicensesPhysicalCPU</li>"
  189. $ReportOutput += "</ul>"
  190.  
  191. # Generic Alert Information
  192. write-host "Collecting Generic Alert Information" -ForegroundColor Gray
  193. $AlertsUnclosedAll = Get-SCOMAlert -Criteria "ResolutionState <> '255'" | Measure
  194. $AlertsUnclosedMonitorBased = Get-SCOMAlert -Criteria "ResolutionState <> '255' AND IsMonitorAlert = '$true'" | Measure
  195. $AlertsUnclosedRuleBased = Get-SCOMAlert -Criteria "ResolutionState <> '255' AND IsMonitorAlert = '$false'" | Measure
  196. $CountUnclosedAlerts = $AlertsUnclosedAll.count
  197. $CountMonitorBasedUnclosedAlerts = $AlertsUnclosedMonitorBased.count
  198. $CountRuleBasedUnclosedAlerts = $AlertsUnclosedRuleBased.count
  199. $ReportOutput += "<p><H3><u>Alerts Overview</H3></p></u>"
  200. $ReportOutput += "<ul>"
  201. $ReportOutput += "<li>Total # Unclosed Alert(s): "
  202. $ReportOutput += "<span style='color:#0000FF'>"
  203. $ReportOutput += "$CountUnclosedAlerts</li>"
  204. $ReportOutput += "<li>Total # Monitor based unclosed Alert(s): "
  205. $ReportOutput += "<span style='color:#0000FF'>"
  206. $ReportOutput += "$CountMonitorBasedUnclosedAlerts</li>"
  207. $ReportOutput += "<li>Total # Rule  based unclosed Alert(s): "
  208. $ReportOutput += "<span style='color:#0000FF'>"
  209. $ReportOutput += "$CountRuleBasedUnclosedAlerts</li>"
  210. $ReportOutput += "</ul>"
  211.  
  212. # Get status of Management Server Health and input them into report
  213. write-host "Collecting Management Health Server States" -ForegroundColor Gray
  214. $ReportOutput += "<span style='color:#DF7401'>"
  215. $ReportOutput += "<p><H2>Unhealthy SCOM Management Servers</H2></p>"
  216. $ReportOutput += "<span style='color:#190707'>"
  217.  
  218. $Count = Get-SCOMManagementServer | where {$_.HealthState -ne "Success"} | Measure-Object
  219. if($Count.Count -gt 0) {
  220.  $ReportOutput += "<span style='color:#0000FF'>"
  221.  $ReportOutput += Get-SCOMManagementServer | where {$_.HealthState -ne "Success"} | select Name,HealthState,IsRootManagementServer,IsGateway | ConvertTo-HTML -fragment
  222. } else {
  223.  $ReportOutput += "<span style='color:#0000FF'>"
  224.  $ReportOutput += "<p> All SCOM Management Servers are healthy.</p>"
  225. }
  226.  
  227. #Set font color back to black
  228. $ReportOutput += "<span style='color:#190707'>"
  229.  
  230. #Get MMA Health Status and pipe unhealthy MMAs (or MMAs in MM) into the report
  231. write-host "Collecting MMA in MM" -ForegroundColor Gray
  232. $MG = get-scommanagementgroup
  233. $criteria = new-object Microsoft.EnterpriseManagement.Monitoring.MonitoringObjectGenericCriteria("InMaintenanceMode=1")
  234. $objectsInMM = $MG.GetPartialMonitoringObjects($criteria.Criteria)
  235. $ObjectsFound = $objectsInMM | select-object DisplayName, @{name="Object Type";expression={foreach-object {$_.GetLeastDerivedNonAbstractMonitoringClass().DisplayName}}},@{name="StartTime";expression={foreach-object {$_.GetMaintenanceWindow().StartTime.ToLocalTime()}}},@{name="EndTime";expression={foreach-object {$_.GetMaintenanceWindow().ScheduledEndTime.ToLocalTime()}}},@{name="Path";expression={foreach-object {$_.Path}}},@{name="User";expression={foreach-object {$_.GetMaintenanceWindow().User}}},@{name="Reason";expression={foreach-object {$_.GetMaintenanceWindow().Reason}}},@{name="Comment";expression={foreach-object {$_.GetMaintenanceWindow().Comments}}}
  236. #$ReportOutput += "<li>$ObjectsFound</li>"
  237.  
  238. $ReportOutput += "<span style='color:#DF7401'>"
  239. $ReportOutput += "<h2>Unhealthy Microsoft Monitoring Agents (MMAs)</h2>"
  240. $ReportOutput += "<span style='color:#190707'>"
  241. $ReportOutput += Get-SCOMAgent | where {$_.HealthState -ne "Success"} | Sort-Object HealthState -descending | select Name,HealthState | ConvertTo-HTML -fragment
  242.  
  243. $SickMMAs = (Get-SCOMAgent | where {$_.HealthState -ne "Success"}).count
  244. If ($SickMMAs -eq 0)
  245.     {
  246.     $ReportOutput += "<span style='color:#0000FF'>"
  247.     $ReportOutput += "All Microsoft Monitoring Agents are healthy."
  248.     }
  249. Else
  250.     {
  251.     $ReportOutput += "<span style='color:#FF0000'>"
  252.     $ReportOutput += "Please check the table 'Microsoft Monitoring Agents (MMAs) in Maintenance Mode(MM)' since some 'unhealthy' MMAs might be only in MM and as such 'Uninitialized'."
  253.     $ReportOutput += "<span style='color:#190707'>"
  254.     }
  255.  
  256.  
  257. $ReportOutput += "<span style='color:#DF7401'>"
  258. $ReportOutput += "<h2>Microsoft Monitoring Agents (MMAs) in Maintenance Mode(MM)</h2>"
  259. $ReportOutput += "<span style='color:#190707'>"
  260. $Agents = Get-scomAgent | where {$_.HealthState -ne "Success"} | Sort-Object HealthState -descending | select Name,HealthState
  261.  
  262. If ($Agents -eq $null)
  263.     {
  264.     $ReportOutput += "<span style='color:#0000FF'>"
  265.     $ReportOutput += "All Microsoft Monitoring Agents are active."
  266.     $ReportOutput += "<span style='color:#FF0000'>"
  267.     $ReportOutput += "<p>Remark: When an Object is only for some minutes out of MM, it may be listed here with the 'MM' status 'No'. This is due to the design of the SCOM database and can't be altered.</p>"
  268.     $ReportOutput += "<span style='color:#190707'>"
  269.     }
  270. Else
  271. {
  272. $AgentTable = New-Object System.Data.DataTable "$AvailableTable"
  273. $AgentTable.Columns.Add((New-Object System.Data.DataColumn Name,([string])))
  274. $AgentTable.Columns.Add((New-Object System.Data.DataColumn HealthState,([string])))
  275. $AgentTable.Columns.Add((New-Object System.Data.DataColumn MM,([string])))
  276. $AgentTable.Columns.Add((New-Object System.Data.DataColumn MMUser,([string])))
  277. $AgentTable.Columns.Add((New-Object System.Data.DataColumn MMReason,([string])))
  278. $AgentTable.Columns.Add((New-Object System.Data.DataColumn MMComment,([string])))
  279. $AgentTable.Columns.Add((New-Object System.Data.DataColumn MMEndTime,([string])))
  280.  
  281. foreach ($Agent in $Agents)
  282.     {
  283.         $FoundObject = $null
  284.     $MaintenanceModeUser = $null
  285.     $MaintenanceModeComment = $null
  286.     $MaintenanceModeReason = $null
  287.     $MaintenanceModeEndTime = $null
  288.         $FoundObject = 0
  289.         $FoundObject = $objectsFound | ? {$_.DisplayName -match $Agent.Name -or $_.Path -match $Agent.Name}
  290.         if ($FoundObject -eq $null)
  291.             {
  292.                 $MaintenanceMode = "No"
  293.                 $MaintenanceObjectCount = 0
  294.             }
  295.         else
  296.             {
  297.                 $MaintenanceMode = "Yes"
  298.                 $MaintenanceObjectCount = $FoundObject.Count
  299.         $MaintenanceModeUser = (($FoundObject | Select User)[0]).User
  300.         $MaintenanceModeReason = (($FoundObject | Select Reason)[0]).Reason
  301.         $MaintenanceModeComment = (($FoundObject | Select Comment)[0]).Comment
  302.         $MaintenanceModeEndTime = ((($FoundObject | Select EndTime)[0]).EndTime).ToString()
  303.             }
  304.         $NewRow = $AgentTable.NewRow()
  305.         $NewRow.Name = ($Agent.Name).ToString()
  306.         $NewRow.HealthState = ($Agent.HealthState).ToString()
  307.         $NewRow.MM = $MaintenanceMode
  308.         $NewRow.MMUser = $MaintenanceModeUser
  309.         $NewRow.MMReason = $MaintenanceModeReason
  310.         $NewRow.MMComment = $MaintenanceModeComment
  311.         $NewRow.MMEndTime = $MaintenanceModeEndTime
  312.         $AgentTable.Rows.Add($NewRow)
  313.     }
  314. }
  315.    
  316. #$ReportOutput += $AgentTable | Sort-Object MM | Select Name, HealthState, MM, MMUser, MMReason, MMComment, MMEndTime | ConvertTo-HTML -fragment
  317. $MMAResults = $AgentTable | Sort-Object MM | Select Name, HealthState, MM, MMUser, MMReason, MMComment, MMEndTime | ConvertTo-HTML -fragment
  318. $ReportOutput += $MMAResults
  319.  
  320.  
  321. # Get Alerts specific to Management Servers and put them in the report
  322. write-host "Collecting Management Server Alerts" -ForegroundColor Gray
  323. $ReportOutput += "<span style='color:#DF7401'>"
  324. $ReportOutput += "<h2>SCOM Management Server Alerts</h2>"
  325. $ReportOutput += "<span style='color:#190707'>"
  326. $ManagementServers = Get-SCOMManagementServer
  327. $SCOMMSAlerts = get-SCOMalert -Criteria ("NetbiosComputerName = '" + $ManagementServer.ComputerName + "'") | where {$_.ResolutionState -ne '255' -and $_.MonitoringObjectFullName -Match 'Microsoft.SystemCenter'}
  328. If ($SCOMMSAlerts -eq $null)
  329.     {
  330.     $ReportOutput += "<span style='color:#0000FF'>"
  331.     $ReportOutput += "No SCOM Management Server Alerts found."
  332.     }
  333. Else
  334. {
  335. foreach ($ManagementServer in $ManagementServers){
  336.  $ReportOutput += "<h3><u>Alerts on " + $ManagementServer.ComputerName + "</h3></u>"
  337.  $ReportOutput += get-SCOMalert -Criteria ("NetbiosComputerName = '" + $ManagementServer.ComputerName + "'") | where {$_.ResolutionState -ne '255' -and $_.MonitoringObjectFullName -Match 'Microsoft.SystemCenter'} | select TimeRaised,Name,Description,Severity | ConvertTo-HTML -fragment
  338. }
  339. }
  340.  
  341. # Get all alerts
  342. write-host "Collecting All Alerts" -ForegroundColor Gray
  343. $Alerts = Get-SCOMAlert -Criteria 'ResolutionState < "255"'
  344.  
  345. # Get alerts for last 24 hours
  346. write-host "Collecting Alerts - Last 24 hrs" -ForegroundColor Gray
  347. $ReportOutput += "<span style='color:#DF7401'>"
  348. $ReportOutput += "<h2>Top 10 Alerts With Same Name - 24 hours</h2>"
  349. $ReportOutput += "<span style='color:#190707'>"
  350. $ReportOutput += $Alerts | where {$_.LastModified -le (Get-Date).addhours(-24)} | Group-Object Name | Sort-object Count -desc | select-Object -first 10 Count, Name | ConvertTo-HTML -fragment
  351.  
  352. $ReportOutput += "<span style='color:#DF7401'>"
  353. $ReportOutput += "<h2>Top 10 Repeating Alerts - 24 hours</h2>"
  354. $ReportOutput += "<span style='color:#190707'>"
  355. $ReportOutput += $Alerts | where {$_.LastModified -le (Get-Date).addhours(-24)} | Sort-Object -desc RepeatCount | select-Object -first 10 RepeatCount, Name, MonitoringObjectPath, Description | ConvertTo-HTML -fragment
  356.  
  357. # Get the Top 10 Unresolved alerts still in console and put them into report
  358. write-host "Collecting Top 10 Unresolved Alerts With Same Name - All Time" -ForegroundColor Gray
  359. $ReportOutput += "<span style='color:#DF7401'>"
  360. $ReportOutput += "<h2>Top 10 Unresolved Alerts</h2>"
  361. $ReportOutput += "<span style='color:#190707'>"
  362. $ReportOutput += $Alerts  | Group-Object Name | Sort-object Count -desc | select-Object -first 10 Count, Name | ConvertTo-HTML -fragment
  363.  
  364. # Get the Top 10 Repeating Alerts and put them into report
  365. write-host "Collecting Top 10 Repeating Alerts - All Time" -ForegroundColor Gray
  366. $ReportOutput += "<span style='color:#DF7401'>"
  367. $ReportOutput += "<h2>Top 10 Repeating Alerts</h2>"
  368. $ReportOutput += "<span style='color:#190707'>"
  369. $ReportOutput += $Alerts | Sort -desc RepeatCount | select-object -first 10 Name, RepeatCount, MonitoringObjectPath, Description | ConvertTo-HTML -fragment
  370.  
  371. # Get the Top 10 Rule Based Closed Alerts and put them into report
  372. Write-Host "Collecting Top 10 Rule Based Closed Alerts" -ForegroundColor Gray
  373. $ReportOutput += "<span style='color:#DF7401'>"
  374. $ReportOutput += "<h2>Top 10 Rule Based Closed Alerts</h2>"
  375. $ReportOutput += "<span style='color:#190707'>"
  376. $RuleBasedClosedAlerts = Get-SCOMAlert -Criteria "ResolutionState = '255' AND IsMonitorAlert = 'False'"
  377. $ReportOutput += $RuleBasedClosedAlerts | Sort Name | Group Name | Sort Count -Descending | Select Count, Name -First 10 | ConvertTo-HTML -fragment
  378.  
  379. # Get the Top 10 Monitor Based Closed Alerts and put them into report
  380. Write-Host "Collecting Top 10 Monitor Based Closed Alerts" -ForegroundColor Gray
  381. $ReportOutput += "<span style='color:#DF7401'>"
  382. $ReportOutput += "<h2>Top 10 Monitor Based Closed Alerts</h2>"
  383. $ReportOutput += "<span style='color:#190707'>"
  384. $MonitorBasedClosedAlerts = Get-SCOMAlert -Criteria "ResolutionState = '255' AND IsMonitorAlert = 'True'"
  385. $ReportOutput += $MonitorBasedClosedAlerts | Sort Name | Group Name | Sort Count -Descending | Select Count, Name -First 10 | ConvertTo-HTML -fragment
  386.  
  387. # Get list of agents still in Pending State and put them into report
  388. write-host "Collecting MMAs In Pending State" -ForegroundColor Gray
  389. $ReportOutput += "<span style='color:#DF7401'>"
  390. $ReportOutput += "<h2>Microsoft Monitoring Agents in Pending State</h2>"
  391. $ReportOutput += "<span style='color:#190707'>"
  392. $ReportOutput += Get-SCOMPendingManagement | sort AgentPendingActionType | select AgentName,ManagementServerName,AgentPendingActionType | ConvertTo-HTML -fragment
  393.  
  394. # List Management Packs updated in last 24 hours
  395. write-host "Collecting Management Packs - Updated Last 24 hrs" -ForegroundColor Gray
  396. $ReportOutput += "<span style='color:#DF7401'>"
  397. $ReportOutput += "<h2>Recently Updated Management Packs</h2>"
  398. $ReportOutput += "<span style='color:#190707'>"
  399. $MPDates = (Get-Date).adddays(-1)
  400. $ReportOutput += Get-SCManagementPack | Where {$_.LastModified -gt $MPDates} | Select-Object DisplayName, LastModified | Sort LastModified | ConvertTo-Html -fragment
  401.  
  402. #End Stopwatch and display total run time
  403. $StopWatch.Stop()
  404. $ElapsedMinutes = $StopWatch.Elapsed.Minutes
  405. $ElapsedSeconds = $StopWatch.Elapsed.Seconds
  406. $ReportOutput += "<span style='color:#DF7401'>"
  407. $ReportOutput += "<h2>Report Creation Time: "
  408. $ReportOutput += "<span style='color:#0000FF'>"
  409. $ReportOutput += "$ElapsedMinutes minutes and $ElapsedSeconds seconds</h2>"
  410.  
  411. #Test for presence of folder 'C:\Server Management'. When not found create it
  412. $Folder = Test-Path -Path "C:\Server Management"
  413. If ($Folder -eq 'True')
  414. ##Folder found no further actions required
  415. {}
  416. Else
  417. ##Folder not present. It will be created now
  418.     {
  419.     md "C:\Server Management" | Out-Null
  420.     }
  421.  
  422. # Take all $ReportOutput and combine it with $Body to create completed HTML output
  423. $Body = ConvertTo-HTML -head $Head -body "$ReportOutput"
  424. $Body | Out-File "C:\Server Management\$ReportDate$ReportTime _SCOM Health Check Report MG $MGName.html"
  425. Invoke-Item "C:\Server Management\$ReportDate$ReportTime _SCOM Health Check Report MG $MGName.html"
  426.  
  427. #Setup and send output as email message to GMAIL
  428. ##REMOVE ALL TAGS IN ORDER TO ENABLE THIS SECTION!!!
  429. ##Update $UserName and $Password for your email server on Gmail
  430. ##Also update '$mailmessage.from' and '$mailmessage.To'. Add with who its coming from and going to
  431. #$SMTPServer = "smtp.gmail.com"
  432. #$SMTPPort = "587"
  433. #$Username = "GMAIL User Name HERE"
  434. #$Password = "GMAIL Password HERE"
  435. #$Body = ConvertTo-HTML -head $Head -body "$ReportOutput"
  436. #$SmtpClient = New-Object system.net.mail.smtpClient($SMTPServer, $SMTPPort);
  437. #$MailMessage = New-Object system.net.mail.mailmessage
  438. #$mailmessage.from = "sender@company.com"
  439. #$mailmessage.To.add("receiver01@company.com")
  440. #$mailmessage.To.add("receiver02@company.com")
  441. #$mailmessage.Subject = "SCOM Daily Healthcheck Report MG $MGName"
  442. #$MailMessage.IsBodyHtml = $true
  443. #$smtpClient.EnableSSL = $true
  444. #$smtpClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
  445. #$mailmessage.Body = $Body
  446. #$smtpclient.Send($mailmessage)
  447.  
  448. #End of script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement