Warm tip: This article is reproduced from serverfault.com, please click

How to fetch appid and password in AZ Cli PowerShell using jmespath?

发布于 2020-12-29 04:57:49

Hello I am trying to create a service account using the below az cli commands. I am trying to fetch the appId and password into a powershell object using Jmespath. This is what I am trying to do.

$serviceprincipalname ="k8ssp"

$spdetails = $( az ad sp create-for-rbac `
--name $serviceprincipalname `
--query [appId, password])

write-output $spdetails
write-output $spdetails[0]

However the Jmespath query fails with the below error

az ad sp create-for-rbac: error: argument --query: invalid jmespath_type value: '[appId'

How can I select both the appId and password into a single object so that I can later split it and use it ?

Questioner
Pradeep Loganathan
Viewed
0
Nancy Xiong 2020-12-29 14:54:44

You can use --query "[appId, password]" -o tsv

$result=(az ad sp create-for-rbac --name $serviceprincipalname --query "[appId, password]" -o tsv)

enter image description here