Last active
September 12, 2024 21:01
-
-
Save KakersUK/d090e1836ffb881d29c9f529b380f795 to your computer and use it in GitHub Desktop.
PowerShell 7 script to stop the PC from going to sleep if there are any active streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plex on Windows Anti-Sleep | |
# | |
# References | |
# Gist: https://gist.github.com/KakersUK/d090e1836ffb881d29c9f529b380f795 | |
# Install PowerShell 7: https://learn.microsoft.com/en-gb/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3#winget | |
# X-Plex-Token: https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/ | |
# Host variables | |
$PlexHost = '127.0.0.1' | |
$PlexPort = 32400 | |
$PlexToken = '' | |
# Create Windows shell object. | |
$WshShell = New-Object -ComObject WScript.Shell | |
# GET the active play session information from our Plex API. | |
$xmlResponseIRM = Invoke-RestMethod "https://${PlexHost}:${PlexPort}/status/sessions?X-Plex-Token=${PlexToken}" -SkipCertificateCheck -Method Get | |
# If the sessions are greater than 0, Plex is streaming. Send a Shift + F15 key combo to keep the PC awake. | |
If([int]$xmlResponseIRM.MediaContainer.size -gt 0){ | |
$WshShell.SendKeys('+{F15}') | |
} |
THANK YOU!
Awesome! Thank you very much!
love the idea of this but cannot get it working, I get the following
Invoke-RestMethod : A parameter cannot be found that matches parameter name 'SkipCertificateCheck'.
At C:\plex-anti-sleep.ps1:17 char:113
- ... tus/sessions?X-Plex-Token=${PlexToken}" -SkipCertificateCheck -Method ...
-
~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
- FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Sounds like you need to update PowerShell:
https://stackoverflow.com/questions/59924142/powershell-iwr-fails-when-attempting-skipcertificatecheck
…On Fri, Mar 8, 2024 at 9:43 PM Ezzzy007 ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
love the idea of this but cannot get it working, I get the following
Invoke-RestMethod : A parameter cannot be found that matches parameter
name 'SkipCertificateCheck'.
At C:\plex-anti-sleep.ps1:17 char:113
- ... tus/sessions?X-Plex-Token=${PlexToken}" -SkipCertificateCheck
-Method ...
-
~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod],
ParameterBindingException
- FullyQualifiedErrorId :
NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/KakersUK/d090e1836ffb881d29c9f529b380f795#gistcomment-4978665>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACQAXRFRE6P2BFTAVNMCTF3YXKOPRBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTEMJUGA2TSOBTU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
hi the script isn't working can you please rectify
Tried everything allowing executionpolicy in PowerShell both versions to remotesigned and unrestricted
allowing in firewall exceptions ,running pwsh.exe as admin shortening time to when task scheduler runs the script ,script runs fine and completes via windows task scheduler
trying on two separate machines
double checked plex tokens and they are fine too
UPDATE: no does not work on any machine plex servers still sleep when streaming from
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup Instructions:
Links can be found in the script's references.
Plex settings:
"Support Away Mode when preventing system sleep" Not too sure on this setting, but I've turned this off to ensure the machine goes to sleep when not being used.