Search code examples
powershellazure-devopsazure-cliazure-repos

How to convert --query return to string (az-devops cli with Powershell)


I'm trying to assign a --query's returned id value into a variable as a string so that I can use the variable to input the id in other commands in Windows Powershell:

$repoID = az repos list --query "`"[?contains(name,'$Name')].id`""
az repos policy approver-count create --repository-id $repoID

but $repoID contains

[
"id value"
]

Would anyone know how to convert the return into a string so that $repoID = "id value" and becomes a valid parameter input?

Thanks in advance!


Solution

  • Please use another output by setting -o tsv

    $repoID = az repos list --query "`"[?contains(name,'$Name')].id`"" -o tsv