Marvel from PowerShell [English]

This is my first post in English :)

After watching the last movie of Marvel, Black Panther, I was starting to search about the world of comics and wrote a small PowerShell module to interact with the Marvel Comics REST API.

Marvel had publish a REST API which allows you to gather data regarding the entire Marvel Comics Universe and to create amazing websites and apps with that free data. For example, you can access to the characters info, comics, comics stories and much more. And you might be wondering what this has to do with PowerShell? Well, I love reading and searching about everything. I knew I had to find a way to add this into the console. So, I created a module to access to all the information from PowerShell console. 😎

Installing the module

The module can be installed from the PowerShell Gallery using the following complex command:

Install-Module -Name PSMarvel

How does it work?

There are a couple of things you will need to setup before you can use the module:

First, setup a Marvel API key (create an account): link. After completing the registration process you’ll have this data:

API keys

With the keys, you can start to consume the API using the cmdlet Invoke-RestMethod. I wrote the following function to start accessing information:

#API Keys and TS
$MarvelTS = New-TimeSpan -End (Get-Date -Year 2018 -Month 1 -Day 1)

#Form the hash as Marvel requires 
$ToHash = $MarvelTS.ToString() + $MarvelPrivate.ToString() + $MarvelPublic.ToString()
$StringBuilder = New-Object System.Text.StringBuilder 
[System.Security.Cryptography.HashAlgorithm]::Create("MD5").ComputeHash([System.Text.Encoding]::UTF8.GetBytes($ToHash)) | % {
$MD5 = $StringBuilder.ToString()

How can you search any character? We’ll use the parameter nameStartsWith with the URL and the apikey like this:

#Call the API gateway
$StartWith = "Spider"
$Url = "$StartWith&apikey=$MarvelPublic&hash=$MD5&ts=$MarvelTS"

And manipulate the data:

$Results = Invoke-WebRequest $Url
$Content = $results.Content
$Output = ConvertFrom-Json $Content
#Display only the name list

The result:

Display only the name list

What does the module contain?

The module has the following commands:

Get-Command -Module PSMarvel
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Find-MarvelCharacter                               1.0.2      PSMarvel
Function        Find-MarvelComic                                   1.0.2      PSMarvel
Function        Get-MarvelCharacter                                1.0.2      PSMarvel
Function        Get-MarvelComic                                    1.0.2      PSMarvel
Function        Get-MarvelRandomCharacter                          1.0.2      PSMarvel


C:\Users\vmsilvamolina> Get-MarvelComic -Title "Iron Fist (2017) #77"

## Comic title:

     Iron Fist (2017) #77

## Description:

SABRETOOTH: ROUND TWO PART 5! CHOSHIN’S crew is wreaking havoc in the heavenly city, and it’s going to take the combined might of IRON FIST, SABRETOOTH and the residents of K’un-Lun to stop him! But will Choshin convince K’un-Lun’s citizens that he is their true champion? Iron Fist’s desperate plea will bring K’un-Lun’s greatest defenders back to the fight…...including SPARROW, the THUNDERER!

## Series:

     Iron Fist (2017 - Present)

## Format:


## Creators:

     Mark Basso / editor
     Ed Brisson / writer
     Jeff Dekal / painter (cover)
     Vc Travis Lanham / letterer
     Mike Perkins / inker
     Andy Troy / colorist


The module is available on github here, feel free to contribute via issues or pull requests.

Hope you enjoyed this module and article! 💪

Disclaimer: Data provided by Marvel. © 2018 MARVEL

Happy scripting!