PowerShell Snippets: Get One Value from GitHub Json

PowerShellThis post is part of the series on PowerShell Snippets.

While looking into uploading a release asset to a GitHub release, I discovered that to do this I needed the internal numeric id for a release and not just the id I’d given it. The element I needed from the GitHub json was id which can be retrieved using the below PowerShell which executes curl and then selects a single element:


$ghAuthorizationToken = "ghp_authorizationtoken"

$ghUser="username"
$ghRepo="repositoryname"
$ghTag="v1.4.2"

$URL= "https://api.github.com/repos/$ghUser/$ghRepo/releases/tags/$ghTag"

$Json=(curl.exe $URL)|ConvertFrom-json

$id=$Json| Select id