Public/Get-SCOMMPFileInfo.ps1

Function Get-SCOMMPFileInfo {
  <#
      .Synopsis
      List version and file path information for all management pack files (*.mp, *.mpb, *.xml).
      .DESCRIPTION
      Will display MP file and version information.
 
      .EXAMPLE
      Get-SCOMMPFileInfo -inDir 'C:\Program Files (x86)\System Center Management Packs' -Verbose | Select Name,DisplayName,Version,FullName | Format-Table
 
      .EXAMPLE
      Get-SCOMMPFileInfo -inDir 'C:\Program Files (x86)\System Center Management Packs' | Select-Object Name,DisplayName,Version,FullName,KeyToken, @{Name="References"; Expression={($_.References.GetEnumerator() | Out-String) } } | Out-GridView -PassThru
 
      The above example will display all of the MP properties in Gridview with the References column displayed in a more friendly format.
 
      .EXAMPLE
      Get-SCOMMPFileInfo -inDir 'C:\Program Files (x86)\System Center Management Packs' | Out-GridView -PassThru | % {& explorer.exe (Split-Path -Parent $_.FullName) }
 
      The above example will present a list of your management packs in Gridview. Once you select one or more items-OK, the folder(s) containing the management pack(s) will be opened with File Explorer.
 
      .EXAMPLE
      Get-SCOMMPFileInfo -inDir 'C:\MySealedMPs' | Format-Table | ConvertTo-Html | Set-Content C:\mpfiles.html; C:\mpfiles.html
 
      The above example will create an HTML report of your MP files then open the HTML file with the default application.
 
      .INPUTS
      System.String, Switch
      .OUTPUTS
      Custom object
      .NOTES
      Author: Tyson Paul
      Blog: https://monitoringguys.com/
      History:
      2020.02.27 - Improved efficiency. Added verbose output.
      2020.02.21 - Added more examples. Removed Gridview and Passthru switches.
      2019.07.29 - Added a few more MP properties to the returned object(s)
      2018.05.30 - Added GridView option as well as some other cleanup.
      .FUNCTIONALITY
      Useful for identifying specific versions of management packs in your local archive.
      .LINK
      Get-SCOMClassInfo
      New-SCOMClassGraph
      Unseal-SCOMMP
  #>



  [CmdletBinding(DefaultParameterSetName='Parameter Set 1',
      SupportsShouldProcess=$true,
  PositionalBinding=$false)]

  Param (
    [Parameter(Mandatory=$true,
        ValueFromPipeline=$false,
        ValueFromPipelineByPropertyName=$false,
        ValueFromRemainingArguments=$false,
        Position=0,
    ParameterSetName='Parameter Set 1')]
    [ValidateNotNull()]
    [ValidateNotNullOrEmpty()]
    [Alias("Path")]
    [string]$inDir

    # deprecated
    # [switch]$GridView=$true,

    # deprecated
    #[switch]$passthru=$true
  )

  [System.Collections.ArrayList]$arrMaster = @()

  $MPFiles = Get-ChildItem -Path $inDir -Recurse -Include *.mp,*.mpb,*.xml
  ForEach ($File in $MPFiles.FullName) {
    Write-Verbose $File

    Switch ($File) {
      {$_ -Match '\.mp$|\.xml$'} {
        $MP = Get-SCManagementPack -ManagementPackFile $File
        break;
      }

      # Get MPB (bundles)
      {$_ -Match '\.mpb$'} {
        #Sometimes bundles cannot be retrieved
        Try {
          $MP = Get-SCManagementPack -BundleFile $File
        }Catch {
          Write-Host "Unable to retrieve file: [ $($File) ]. FullName.Length:[$($File.Length)]" -F Red
          break;
        }
      }
    }#end Switch
    $obj = New-Object PSCustomObject
    $obj | Add-Member -Type NoteProperty -Name Name -Value $MP.Name
    $obj | Add-Member -Type NoteProperty -Name DisplayName -Value $MP.DisplayName
    $obj | Add-Member -Type NoteProperty -Name Version -Value $MP.Version
    $obj | Add-Member -Type NoteProperty -Name FullName -Value $File
    $obj | Add-Member -Type NoteProperty -Name Description -Value $MP.Description
    $obj | Add-Member -Type NoteProperty -Name ID -Value $MP.ID.GUID
    $obj | Add-Member -Type NoteProperty -Name KeyToken -Value $MP.KeyToken
    $obj | Add-Member -Type NoteProperty -Name DefaultLanguageCode -Value $MP.DefaultLanguageCode
    $obj | Add-Member -Type NoteProperty -Name References -Value $MP.References

    Write-Verbose "$File"
    $Null = $arrMaster.Add($obj)
  }#end ForEach

  Return $arrMaster
}