posh-starwars module

Diving deep into RESTFULL api brought me all the way from my powershell prompt to the intergalactic universe of Star wars.

How to join your favorite science fiction movies and your favorite automation tool, together, in the same prompt!

This is one of these posts, that has been in my “draft box” for so long, that if it could, it would have had grown a beard by now!

 

Why this module you may ask? Well, if you have been following along, I have been working quite a few with REST API these last months. In case you don’t know what rest api is, It is a very cool technology which allows you to query information stored on HTTP end point by usings HTTP requests. I know, this can sound a bit ‘difficult’, but believe me, it is super easy!

REST has been used more and more by IT pros (Read powershell scripters developpers), especially with Microsoft’s new cloud technolgies. I got to know REST while developping Powershell automation scripts for Sharepoint Online and Office 365.

Quite often when we want to gather data from the internet, we do have a limited set of automation possibilities, us, the PowerShell scripters developpers. Gladly, the cloud is full of REST end points, and we can get our information directly from there.

Ok, and what about this Star Wars PowerShell module?

Well, basically, I was curious what other REST points would be available for us in the cloud. I already knew about Youtube and Facebook, but I was curious. And then I found http://Swapi.co “The star wars API”. As it names suggest, it is a API, which host a Star Wars database accessible through Restless API.

The main drawback of the Swapi.co API is that it doesn’t use ODATA to structure the calls. Which means that there is no well knowed format for queries that is respected, which made things a bit more difficult when I was trying to filter things out.

As soon as I saw that, I open my ISESteroids console, and started to code immediately. Shortly after, I finished the first version of the  Posh-StarWars PowerShell module.

Do you want to participate to the posh project? I have made it publicly available on my GitHub account here.

I also would like to point out that all the credits go out to “phalt” who created the initial project and made all of this possible (original project is available here) You can directly access the swapi web site here. I simply wrote Powershell wrappers around the great work from “phalt”

What can the Star Wars PowerShell module do?

Posh-StarWars cmdlets:

This very first version comes with 7 cmdlets.

Each of the cmdlet comes with the same set of parameters:

The cmdlets come actually with a few more parameters, but I am still working on these ones. The two main parameters are:

  • id
  • name

Get information on the Star Wars characters using PowerShell:

Ok, not that you might need this in a production environment one day (except if you work for Disney maybe), but as a major geek that I am, sometimes I ask my self very very serious questions like: How tall is Master Yoda actually? Can I retrieve that information using PowerShell? Yes you can!

Use Get-SWPeople -Name Yoda

powershell star wars Yoda height

powershell star wars Yoda height

Get information on the Star Wars planets using PowerShell:

Have you ever asked your self what is the diameter of Tattooine? And could I get that information using PowerShell? YES!

get all star wars planet information using powershell

retrieve Tatooine’s diameter using PowerShell

 

Get information on the Star Wars Star ships using PowerShell:

Have you ever asked your self what is the max speed that the Millennium Falcon could reach? Could I get that information using PowerShell? YES!

get star wars star ship information using powershell

Max speed of the Millenium Falcon

 

Get information on the Star Wars Star planets and convert them into “Wookie”!

Haha, I loved this one! The developper which created the SWAPI.CO api, added the possiblity to convert everything into “Wookie”, just in case, if any of use preferes that language to it’s native one.

Here is an illustration of it:

Star wars data in wookie

Since there is no ODATA, all the filtering is actually done after the data is retrieved (which means most right. bad practice boooo. yeah I know!) This means you might bump into issues while converting your data into “wookie” . I’ll recommend using the ID parameter when you want to retrieve information in wookie.

Next steps and open points / questions:

I have been looking into REST end points such as IMDB in order to get more information on caracters (especially pictures) but unfortunatley the access to their database is not free through the RESTFULL API 🙁

If anyone has a suggestion on where I could retrieve pictures from and other infos, my ears are all open!

Have fun!