Skip to content

Instantly share code, notes, and snippets.

@matt2005
Created September 15, 2017 21:28
Show Gist options
  • Save matt2005/021f22eb10514091d37715d6a7cc6f06 to your computer and use it in GitHub Desktop.
Save matt2005/021f22eb10514091d37715d6a7cc6f06 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