I wrote a Powershell script to report on movies recently added to your Plex library. It uses the Plex API as well as OMDBapi.com (the Open Movie Database) to fetch information on each movie. Powershell is Windows functionality, so this will only work on Windows unfortunately. I have it set up on my server as a Scheduled Task that runs every Friday at 10am, and sends the email to a Google Group I set up to include all the people I share my library with. See notes below for more info.
This should be relatively easy to set up for someone running their Plex Server on a Windows machine, but if you’ve never used Powershell before, here’s what you need to do:
Download PlexCheck.ps1 to your computer from here.
Change the .ps1 extension on Get-CredentialFromWindowsCredentialManager.ps1 to .psm1, and save it to C:\Users[username]\Documents\WindowsPowershell\Modules\Get-CredentialFromWindowsCredentialManager.
Open a Powershell prompt and run the command
Set-ExecutionPolicy Unrestricted
Store the credentials of the email address you want to send the email from in Windows Credential Manager. Instructions here. You should store them with the name “PlexCheck” to avoid having to specify a credential name when running the script.
Run the script! You can run from a Powershell prompt, or by right-clicking and selecting Run.
This currently only allows one recipient. To avoid having to modify the script or Scheduled Task all the time, I set up a Google Group, added my friends to that, and set that as the lone recipient in my Scheduled Task.
Default behavior:
.\PlexCheck.ps1
This will run the script with default values:
It will assume you’re running it from the same box that your Media Server is running on. As such, the default IP is 127.0.0.1.
It uses the default Plex port, 32400.
The sender email address will be what’s defined in your credentials in Windows Credential Manager.
The to address, unless otherwise specified, will be the same as the sender address. Change it at run-time.
This defaults to Gmail’s SMTP server settings, but that can be overridden with parameters. To send from a Gmail account, “Access for less secure apps” must be turned on. Instructions here.
This will send over SSL, and this can’t be overridden. Just do it.
This defaults to a 7-day lookback period, but that can be changed, if that’s what you’re into.
Here’s an example of how to run it with all the values changed:
@sup3rmark
I managed to get most of the script working, but ran into a few issues.
Sometimes, when i run the PlexCheck.ps1 script (as administrator) i get:
~windowsCredentialManager.psm1 : No credentials where found in Windows Credential Manager for TargetName:
At C:\PlexCheck.ps1:56 char:9
when that does go through, i then and always get:
Invoke-WebRequest : 401 Unauthorized
At C:\PlexCheck.ps1:71 char:1
+Invoke=WebRequest “$url’:$port/library/recentlyAdded/”
so, i tested with how i have my file setup. for my plex location, i have localhost rather then 127.0.0.1 as its the same thing… but all my pages load as localhost with everything else.
i then wrote a full url string based on what the code calls for: localhost:32400/library/recentlyAdded/
and i get 401 Unauthorized.
what is the full command string you’re using? localhost instead of the IP shouldn’t be a problem. shouldn’t be a plex credentials issue either, since you don’t need those to make the API call.
screenshot?
the credentials (windows Credentials (generic) i entered; might be an issue? i entered Internet or network address as: PlexCheck, User name as the email address i want to send to (as a login?) and password of the email account.
running in WIN 10, powershell is running as admin, permission is set as unrestricted. only change in the code i made was the email address to send the report instead of test@test.com (default) i entered my gmail.
@m1e1w1 so, the email address you should be putting in Credential Manager should be the From address. you don’t need to/shouldn’t alter the code to set the To address, just pass that as a parameter. same as the URL: if you don’t want to use the 127.0.0.1 IP (which should be totally fine with what you’ve said about your setup), you can also pass that in:
.\PlexCheck.ps1 -emailTo recipient@test.com -url localhost
try downloading the script again and using it as-is, passing in the values you want instead of modifying it. i’d also recommend running it from your Documents folder instead of root c:. if that still doesn’t work, try pointing your web browser (on the server itself) at 127.0.0.1:32400/library/RecentlyAdded and see if that returns the expected XML.
@sup3rmark
i just tried 127.0.0.1:32400/library/RecentlyAdded and localhost:32400/library/RecentlyAdded URL and i dont get an XML page. just 401 unauthorized. i will drop new scripts too, but i think i will need to resolve the 401 error before i even get data to email.
@m1e1w1 the 401 is definitely something to do with your server, not the script… you might be using a different port or something. you’re running the script on the PMS, right? go to your plex server settings page, hit up the Remote Access tab, and tell me what it says next to Private.
feel free to hit me up on hangouts to discuss this more easily - [myusername]@gmail.com
@sup3rmark
after checking the thread you posted, it reviews if i have a pin enabled, and i do not. i did try and enable a pin, and then removed it, rebooted the PMS, still getting 401. I’ve also tried to see if the network subnet was an issue, and for the PMS machine, i was on the same subnet as my router. i do have a synology nas that has 2 subnet addresses, 1 matches the router and the other is a VPN’s subnet. i disabled the VPN, tested and that made no difference.
i checked my router just to be sure that port 32400 was open for any connection, and it is.
still have 401 unauthorized when using the url: localhost or 127.0.0.1 and :32400/library/recentlyAdded/ as the script requires.
@m1e1w1 unfortunately, i don’t know if i can help you with that issue. the problem you’re having is with your server, and is unrelated to the script. good luck!
Sup3rmark script looks nice. But i cant get it work.
My server is standard Windows 7 with PMS. I get an error when i run it.
What could it be?
Could it be the version of powershell or something else?
I didn’t edited something only the emailaddress in param. Its just running on my localhost with standard port internal 32400.
Just searched the internet and it could be the version. On windows 7 powershell 2.0 is installed. You could install powershell 3.0 manual. I will try today.
Indeed you have to install Powershell 3.0 or you will get the error like i did. I am going to test it further.
The script creates a library.xml that is fine but i get a few errors with the credentials.
I created a credential named plexcheck with username: my emailaddress and password.
This is very cool. I had to massage it a little to get it to work, and it helps to be able to actually read the error messages and understand what it is asking for.
the one thing that is left out of the instructions (for newbs like me) is that you need to get an APIKey and add that to the $omdbURL so that the website will actually respond to your request. Also, if you are going to schedule this as a task, you should put your token in the script instead of requesting it as a parameter.
@sup3rmark , thanks for putting this together. This is going to get regular use!
I’ve found a few things that caused me some pain, and thought i would share: The way this is written, If there is a TV series that has the same name as a movie, the Series will show with the information for the move and not the series. I’ve been able to correct that, i modified the line (only do this in the $tvshows section) $omdbURL = “omdbapi.com/?apikey=xxxxxxx&t=$($show.name)&r=JSON”
modify this to: $omdbURL = “omdbapi.com/?apikey=xxxxxxx&t=$($show.name)&type=series&r=JSON”
adding the type makes is look for the title as a series instead of the default movies.
Again, this is an awesome script to send a notice to users.