-
Azure CLI uses
-query
argument to execute aJMESPath
queryJMESPath
=> JSON query language.-query
argument is supported by all commands in the Azure CLI.
-
Return type
- JSON Array, no order guarantee.
-
Projection
- E.g.
select
in LINQ
az vm list --query '[].{name:name image:storageProfile.imageReference.offer}'
- E.g.
-
Filtering
- E.g.
where
in LINQ
az vm list --query "[?starts\_with(storageProfile.imageReference.offer, 'WindowsServer')]"
- E.g.
-
Combine project + filter
az vm list --query "[?starts\_with(storageProfile.imageReference.offer, 'Ubuntu')].{name:name, id:vmId}
- Better option if you intend to write code to find connection information for a specific application instance.
- Flow:
-
Connect
- You need
azure.auth
file (JSON file describing, secret, key url's etc) - You can create like this:
az ad sp create-for-rbac --sdk-auth > azure.auth
- Then
Azure azure = Azure.Authenticate("azure.auth").WithDefaultSubscription();
- You need
-
See VMs
var vms = await azure.VirtualMachines.ListAsync(); foreach(var vm in vms) { Console.WriteLine(vm.Name); }
-
Gather virtual machine metadata to determine the IP address
INetworkInterface targetNic = targetVm.GetPrimaryNetworkInterface(); INicIPConfiguration targetIpConfig = targetNic.PrimaryIPConfiguration; IPublicIPAddress targetIpAddress = targetIpConfig.GetPublicIPAddress(); Console.WriteLine($"IP Address:\t{targetIpAddress.IPAddress}");
-