Public/Show-SCOMModules.ps1

Function Show-SCOMModules {
  <#
      .Synopsis
      Will display all known modules contained in all sealed management packs as well as basic schema information.
      Based on the original script found here: http://sc.scomurr.com/scom-2012-r2-mp-authoring-getting-modules-and-their-configurations/
      .EXAMPLE
      PS C:\> Show-SCOMModules
 
      .EXAMPLE
      PS C:\> Show-SCOMModules | Out-GridView
 
      .NOTES
      Author: Tyson Paul
      Blog: https://monitoringguys.com/
      Original Date: 2017.12.13
 
      History: 2018.01.22: Refined.
      2017/12/13: First version
  #>



  #############################################
  Function Get-ModuleRunasProfileName {
    Param(
      $Module,
      $Profiles
    )
    $ModuleRunAs = $Profiles | Where-Object { $_.Id.Guid -eq $module.RunAs.Id.GUID }
    Return ($ModuleRunAs.Name+";"+$ModuleRunAs.DisplayName)
  }
  #############################################

  $collection=@()
  $RAAP = Get-SCOMRunAsProfile
  ForEach ($MP in (Get-SCManagementPack | Where-Object{$_.Sealed -eq $True})) {
    ForEach($Module in ($MP.GetModuleTypes() | Sort-Object -Property Name | Sort-Object -Property XMLTag)) {
      $RunAs = ''
      $Object = New-Object PSObject
      $Object | Add-Member Noteproperty -Name Module -Value $Module.Name
      $Object | Add-Member Noteproperty -Name ManagementPackName -Value $MP.Name
      $Object | Add-Member Noteproperty -Name Accessibility -Value $Module.Accessibility

      If ([bool]$Module.RunAs){
        $RunAs = Get-ModuleRunasProfileName -Module $Module -Profiles $RAAP
      }
      $Object | Add-Member Noteproperty -Name RunAs -Value $RunAs
      $Object | Add-Member Noteproperty -Name ID -Value $Module.ID

      if($null -ne $Module.Configuration.Schema) {
        #
        $set = ($Module.Configuration.schema.split("<") | Where-Object {$_ -match "^xsd:element.*"} | `
        ForEach-Object -Process {$_.substring($_.indexof("name")).split("=")[1].split()[0]})
        $Object | Add-Member Noteproperty Schema $set
      }
      $Object | Add-Member Noteproperty -Name Managed -Value $Module.Managed

      $collection += $object
    }
  }

  Return $collection
}