Get Movie Information from Powershell

I recently have been messing around with Powershell and during my scripting tests, I came across a cmdlet called Invoke-WebRequest. It is an extremely powerful cmdlet that can grab data from a web page or web service. As I started to read about it, I decided that it would be neat to grab XML data from a website and display it in Powershell. During my search for an api, I came across http://www.omdbapi.com/, which is a free service that contains movie information.

As you can see, the URL is extremely easy to use for this example:

    http://www.omdbapi.com/?t=FIRST PARAMETER&y=&plot=SECOND PARAMETER&r=xml

First Parameter: Movie Title
Second Parameter: Full or Short(Plot Description)

Once my two parameters were set, I just needed to request the page and select which XML element I wanted to display.

Script:

Function Get-MovieInfo
{
Param(
    [Parameter(Mandatory=$true,Position=0)] $MovieName,
    [Parameter(Position=1)] [ValidateSet('full','short')] $Plot ="short"
    )
( [ xml ] (Invoke-WebRequest "http://www.omdbapi.com/?t=$MovieName&y=&plot=$Plot&r=xml")).root.movie
}

Now you have a Powershell function that you can use to grab movie information!
EXAMPLE:

Get-MovieInfo 'Altered States' -Plot Full

I hope this helps someone!

3 Comments

  1. Hi Jose,

    Nice job creating this.
    I get this error:
    Invoke-WebRequest : No API key provided.

    I need to contact that site for a API key, but how do I add to the string?

    Thanks,
    Regan

    • Jose Espitia

      April 3, 2019 at 2:46 pm

      Hi Regan,
      This used to work in 2015 but I guess they now require an API key. Here is the updated script that you can use to include an API key:
      Function Get-MovieInfo
      {
      Param(
      [Parameter(Mandatory=$true,Position=0)] $MovieName,
      [Parameter(Mandatory=$true,Position=2)] $API,
      [Parameter(Position=1)] [ValidateSet('full','short')] $Plot ="short"
      )
      ( [ xml ] (Invoke-WebRequest "http://www.omdbapi.com/?apikey=$API&?t=$MovieName&y=&plot=$Plot&r=xml")).root.movie
      }

      Then all you have to do is include your API key with the API parameter as shown below:
      Get-MovieInfo ‘Altered States’ -Plot Full -API ‘YOUR_API_KEY_HERE’

      • Thanks Jose!

        Getting movie info is working for me. However, for getting series and episode info I am not using the correct format. Do you see what I am missing for getting series Reacher season 1 and Episode 2?

        Invoke-RestMethod “http://www.omdbapi.com/?apikey=$key&t=Reacher&type=series&plot=full&Season=1Episode=2”
        Thanks, Regan

Leave a Reply