Skip to content

Instantly share code, notes, and snippets.

@freeload101
Forked from matt2005/plextoken.ps1
Created August 24, 2022 16:58
Show Gist options
  • Save freeload101/fe2e7ce5247bbed6676a74487f98a66d to your computer and use it in GitHub Desktop.
Save freeload101/fe2e7ce5247bbed6676a74487f98a66d to your computer and use it in GitHub Desktop.
Plex x-token
$Credential=Get-Credential -Message 'Plex Credentials'
$url = "https://plex.tv/users/sign_in.xml"
$BB = [System.Text.Encoding]::UTF8.GetBytes($('{0}:{1}' -f $Credential.GetNetworkCredential().Username,$Credential.GetNetworkCredential().Password))
$EncodedPassword = [System.Convert]::ToBase64String($BB)
$headers = @{}
$headers.Add("Authorization","Basic $($EncodedPassword)") | out-null
$headers.Add("X-Plex-Client-Identifier","HASS") | Out-Null
$headers.Add("X-Plex-Product","Home Assistant") | Out-Null
$headers.Add("X-Plex-Version","V1") | Out-Null
[xml]$res = Invoke-RestMethod -Headers:$headers -Method Post -Uri:$url
$token = $res.user.authenticationtoken
Return $token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment