SCOM Console Web Page View: index of all rules and monitors with knowledge articles

Required:

Create a new Rule.
Create a new MP with name: “IndexOfWorkflowKnowledge”


Rule Name: GenerateWorkflowIndex Timed PowerShell Script Rule
Rule Target: Management Server
Rule is not enabled.

<#
    Script: ExportAllMPWorkflowKnowledge_w_Index.ps1
    Author: Tyson Paul
    Blog: https://monitoringguys.com/
#>


########################################################################################################
Function LogIt {
  [CmdletBinding(DefaultParameterSetName='Parameter Set 1', 
      SupportsShouldProcess=$true, 
      PositionalBinding=$false,
      HelpUri = 'http://MonitoringGuys.com/',
  ConfirmImpact='Medium')]
  Param 
  (
    [int]$EventID, 

    [Parameter(Mandatory=$true, 
    ParameterSetName='Parameter Set 1')]
    [ValidateRange(0,4)]
    [int]$Type, 
    
    [Alias("Message")] 
    [string]$msg = 'No message specified.', 
    
    [bool]$Proceed, 
    
    $Line
  )

  If ($Proceed -AND (($EventIDFilter -match $EventID) -OR ($EventIDFilter.Length -eq 0) )) {
    $api = New-Object -ComObject MOM.ScriptAPI
    $output = @"
Message: $msg

ThisScriptInstanceGUID: $ThisScriptInstanceGUID
ScriptLine: $Line
Running As: $whoami

WriteToEventLog: $WriteToEventLog		

Any Errors: $Error

"@

    If ($output.Length -gt $maxLogLength){
      $output = ($output.Substring(0,([math]::Min($output.Length,$maxLogLength) )) + '...TRUNCATED...')
    }
    $api.LogScriptEvent("$ScriptName",$EventID,$Type,$output )
  }#End If Proceed. Will skip all this if not enabled.
}
########################################################################################################
Function _LINE_ { 
  $MyInvocation.ScriptLineNumber 
}
########################################################################################################



[bool]$WriteToEventLog = $False

[int]$info = 0
[int]$Critical = 1
[int]$warning = 2
[string]$whoami = whoami.exe
[int]$maxLogLength = 31000 #max chars to allow for event log messages
$ThisScriptInstanceGUID = [System.GUID]::NewGuid().ToString().Substring((35 ) -5).ToUpper()
$outfolder = 'C:\Windows\Temp\SCOMHelper\Export-SCOMKnowledge\scom_alerts_and_knowledge'
$ScriptName = 'ExportAllMPWorkflowKnowledge_w_Index.ps1'

LogIt -EventID 9990 -Type $info -Proceed $WriteToEventLog -msg "Script Begin... `n" -LINE $(_LINE_); $Error.Clear()
Try {
  Import-Module OperationsManager -ErrorAction Stop
  Import-Module SCOMHelper -ErrorAction Stop
} Catch {
  LogIt -EventID 9997 -Type $warning -Message "Failed to load the required modules. Exiting." -Proceed $true; $Error.Clear()
}

$MPs = Get-SCOMManagementPack #-name *utility*

If (-NOT (Test-Path $outfolder -PathType Container) ){
  Try {
    New-Item -Path $outfolder -ItemType Directory -ErrorAction Stop
  } Catch {
    LogIt -EventID 9997 -Type $warning -Message "Failed to create output directory: [$($outfolder)]. Exiting." -Proceed $true; $Error.Clear()
  }
}

ForEach ($MP in $MPs) {
  $Tag = "$($MP.Name)_($($MP.Version.ToString()))"
  . Export-SCOMKnowledge -OutFolder $outfolder -ManagementPack $MP -Topic $Tag 
}


Function Create-IndexPage {
  param (
    [string]$Directory = (Read-Host "Enter the directory path")
  )

  $files = Get-ChildItem $Directory | Where-Object { !$_.PSIsContainer -and ($_.Name -notmatch 'index.html')}
  $indexPage = "<!DOCTYPE html><html><head><title>Index Page</title></head><body><h1>Index Page</h1><table><tr><th>Hyperlink</th><th>File Size (KB)</th><th>Number of Rows</th></tr>"
  
  foreach ($file in $files) {
    $fileContent = Get-Content $file.FullName #-Raw
    $rowCount = ($fileContent | Select-String -Pattern "<tr>").Count
    If ($rowCount -eq 0) {
      continue
    }
    $indexPage += "<tr><td><a href='$($file.Name)'>$($file.Name)</a></td><td>$(($file.Length/1KB).ToString("0.00"))</td><td>$rowCount</td></tr>"
  }
  
  $indexPage += "</table></body></html>"
  $indexpath = "$Directory\index.html"
  Try {
  
    Set-Content -Path $indexpath -Value $indexPage
    LogIt -EventID 9992 -Type $info -Proceed $WriteToEventLog -msg "Successfully wrote index data to: [$($indexpath)] `n" -LINE $(_LINE_); $Error.Clear()    
  } Catch {
    throw $_
  }
}

Try {
  Create-IndexPage -Directory $outfolder
} Catch {
  LogIt -EventID 9997 -Type $warning -Message "Failed to create index page in output directory: [$($outfolder)]. Exiting." -Proceed $true; $Error.Clear()
}

LogIt -EventID 9991 -Type $info -Proceed $WriteToEventLog -msg "Script End. `n" -LINE $(_LINE_); $Error.Clear()


Override: ENABLE for one specific mgmt server to start with, the one you connect to with your Console. Add additional mgmt servers if needed.


Create a new Web Page View within your new custom management pack folder, which gets created automatically.

Verify that you can retrieve the MP and export it to a temp location:

#Verify MP exists
Get-SCOMManagementPack -Name IndexOfWorkflowKnowledge

#Export MP to xml in temp location
Get-SCOMManagementPack -Name IndexOfWorkflowKnowledge | Export-SCOMManagementPack -Path 'C:\Temp\Export'


Edit the location of web page URL; replace with the location of the index file as shown:


New URL value:
file:///C:/Windows/Temp/SCOMHelper/Export-SCOMKnowledge/scom_alerts_and_knowledge/index.html


Save the .XML file. Then import into SCOM.

Import-SCOMManagementPack -Fullname 'C:\Temp\Export\IndexOfWorkflowKnowledge.xml'


Enjoy the new workflow index



NOTE: In my lab, I log into my actual mgmt server to use the Console. If your Console is separate from your mgmt server, you might want to use an alternate path like a common file share or the path to your Web Console server for the $outfolder value and adjust the URL in the MP accordingly.

Example: My Web Console server is “Web21.contoso.com”. Set $outfolder to be:
\\Web21.contoso.com\C$\Program Files\Microsoft System Center\Operations Manager\WebConsole\Dashboard\scom_alerts_and_knowledge


Here you can see that my files have populated on my Web Console server and I’ve set the directory authentication requirements to Anonymous so that I don’t have to authenticate every time I view the index page.


Download example MP here:

Download “IndexOfWorkflowKnowledge”

IndexOfWorkflowKnowledge.zip – Downloaded 842 times – 3.91 KB

Leave a Reply

Your email address will not be published. Required fields are marked *