Reputation: 1995
When i run the following command in azure, I want to place the value of the "name" in a variable like $ipconfigname. The output lists out many other values but I only need this one value "name" in the variable, how can i accomplish this?
az network nic ip-config list -g rg01 --nic-name vmnic01
Upvotes: 2
Views: 3833
Reputation: 31434
Well, when you use the list
command, it means the output must be a list no matter how many members it has. So as you want, the variable $ipconfigname
actually is a list of the config name. You can use the Azure CLI command to set the variable like below only with the name list:
$ipconfigNames = az network nic ip-config list -g rg01 --nic-name vmnic01 --query "[].name" -o tsv
Upvotes: 2
Reputation: 1469
The az cli outputs JSON so if you run your command from a PowerShell prompt you can use ConvertFrom-Json to create an object from the output and then get the property you need
$IpConfig = az network nic ip-config list -g rg01 --nic-name vmnic01 | ConvertFrom-Json
$IpConfigName = $IpConfig.name
Upvotes: 4