View All Module Details

by Feb 1, 2022

powershellgallery.com is a great place to find new free PowerShell extension modules that add new cmdlets to your PowerShell.

However, it can become cumbersome to view all module details in the web interface. That’s why it can be helpful to retrieve module information via RESTful webservice.

Here is a script that takes the name of (any) module hosted in the PowerShell Gallery. It then retrieves all the detail information (such as version history, download counts, dates of updates, and release notes) and prepares them in a way that make the information easily accessible. In particular, the retrieved XML-based information is converted to simple objects:

# replace module name with any module name hosted
# in the PowerShell Gallery (https://powershellgallery.com)
$ModuleName = 'MicrosoftTeams'

$baseUrl = 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='
$escaped = [Uri]::EscapeDataString("'$ModuleName'")
$url = $baseUrl + $escaped

# properties to exclude (add or remove as needed)
$blacklist = 'FileList', 'Tags'

$data = Invoke-RestMethod -Uri $url -UseBasicParsing | 
ForEach-Object {
  $hash = [Ordered]@{}
  $moduleInfo = $_.Properties 
  foreach($_ in $moduleInfo.PSObject.Properties)
  {
    # name of property
    $name = $_.Name
    # if it is in blacklist, skip and continue with next property
    if ($name -in $blacklist) { continue }
# if it is the property "name", then skip 
# all remaining (xml default properties)
    if ($name -eq 'Name') { break }

    # if type is "xmlelement", retrieve underlying text value in #text
    if ($_.TypeNameOfValue -eq 'System.Xml.XmlElement')
    {
      $hash[$name] = $moduleInfo.$name.'#text'

      # if a datatype is assigned, try and convert to appropriate type
      if ($moduleInfo.$name.type -like 'Edm.*')
      {
        $typename = $moduleInfo.$name.type.replace('Edm.','')
        $hash[$name] = $hash[$name] -as $typename
      }
    }
    else
    {
      $hash[$name] = $_.Value
    }
  }

  # convert a hash table to object and return it
  [PSCustomObject]$hash
}

$data | Out-GridView


Twitter This Tip! ReTweet this Tip!