This command gives all NIC names in the Resource group
az network nic list --resource-group "RG_TEST" --query "[0].name"
I want to get only NIC names contains the below string
String: NIC_PROD_TEST
After my workaround around this, I was able to retrieve results for a particular string by using the below query.
Eg: String: 'new'
Use "query "[?contains(name, 'string')].name" as shown below:
az network nic list --resource-group <resourcegroupName> --query "[?contains(name, 'new')].name"
Output:
If you want to get nic name starts with a particular string, you can use
"query "[?starts_with(name, 'string')].name"
az network nic list --resource-group <resourcegroupName --query "[?starts_with(name, 'new')].name"
Output:
Reference: MSDoc
Related
I am query for resources in a subscription as follows:
(az resource list --subscription <subscription-id> --query "[?
type=='Microsoft.Web/sites'] "| ConvertFrom-Json)
But i want to put a second query parameter like the following
(az resource list --subscription <subscription-id> --query "[?
type=='Microsoft.Web/sites'&& resourcegroup== $resourcegroup.name ]"|
ConvertFrom-Json)
How can i do this ?
For querying multiple parameters you can use az graph query in azure cli as below and I followed Microsoft-Document:
Firstly, Set account subscription as below:
az account set --name "XX"
XX- Subscription name.
Now query to get resources:
az graph query -q "Resources | where type=~ 'microsoft.web/sites' | project resourceGroup, name"| ConvertFrom-Json
Please try by using the Pipe expression (|) to separate each condition. Your command would be something like:
(az resource list --subscription <subscription-id> --query "[?
type=='Microsoft.Web/sites'] | [?resourceGroup=='$resourcegroup.name']" |
ConvertFrom-Json)
Please ensure that you are using proper casing for property names (e.g. resourceGroup instead of resourcegroup) and string values are inside single quotes.
Here's the command I used to get storage accounts in a resource group in my Azure Subscription:
az resource list --query "[? type=='Microsoft.Storage/storageAccounts'] | [?resourceGroup=='my-resource-group-name']"
I created an aks using az cli with minimal parameters and specified a node-count and auto scaling. This created a nodepool and VMSS etc. and an accompanying vnet and subnet automatically.
How do I find out the created vnet and subnet using az cli?
az aks nodepool list --cluster-name aks -g rg-aks
report vnetSubnetId and podSubnetId as null.
Using
az vmss list
does show the subnet but I haven't found any properties of the vmss linking it to the nodepool or aks cluster to enable finding it.
The autogenerated name is something like:
aks-nodepool1-15343534-vmss
Which I guess I could filter for along the lines of aks-nodepool1-*-vmss but that seems dodgy and flaky.
I have tested in my environment
The VNET is created along with the VMSS in a different resource group which starts with MC_
To get the subnet ID, you can use the below script:
$CLUSTER_RESOURCE_GROUP = az aks show --resource-group RGName --name AKSClusterName --query nodeResourceGroup -o tsv
$VMSS_NAME = az vmss list -g $CLUSTER_RESOURCE_GROUP --query "[0].name"
az vmss show -g $CLUSTER_RESOURCE_GROUP -n $VMSS_NAME --query virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].subnet.id
I have resource name , but I have to find resource group to which resource belongs. It needs to be done using az cli
You can use the command below to list resources by resource name :
az resource list -n '<resource name>'
So that you can find resourceGroup property in result:
In addition to other answers provided, if you wanted to filter the results of az resource list to show just the resource group name, you could query the json output for the resourceGroup key and then output as tab-separated values.
az resource list -n resource-name --query "[].resourceGroup" -o tsv
Which will just output like this:
ked#mac:~/repos|master ⇒ az resource list -n my-resource --query "[].resourceGroup" -o tsv
my-rg
Here's the azure documentation that shows how to format output.
I would like to get the public IP of an Azure Function in powershell, how this can be done? I saw several examples for VMs but not a function, thanks
Please try the following:
$ips = [System.Net.Dns]::GetHostAddresses("function-getiotdata.azurewebsites.net")
$ips.IPAddressToString
Update:
Also, if you are using a service plan, you can try the following to obtain the outbound IP:
az webapp show --resource-group <group_name> --name <app_name> --query outboundIpAddresses --output tsv
az webapp show --resource-group <group_name> --name <app_name> --query possibleOutboundIpAddresses --output tsv
Please keep in mind that the address might change if you make changes in the service plan, e.g. delete the function, change service tier etc...
I created a new Azure container instance (ACI) with a new vnet and subnet by Azure CLI
I deleted ACI from Azure portal and now Im trying to delete subnet but gives me the following errors:
Failed to delete subnet 'SubnetNAme'. Error: Subnet SubnetNAme is in use by aci-network-profile-VNETNAME-SubnetNAme/eth0/ipconfigprofile and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.
If I tried to access aci-network-profile-VNETNAME-SubnetNAme/eth0/ipconfigprofile, it tells me that doesnt exist this resource:
Details
The resource was not found, it may have been deleted. If this was launched from a pinned tile on the dashboard, it should be removed.
For your issue, instead of finding the aci-network-profile-VNETNAME-SubnetNAme/eth0/ipconfigprofile in the portal, you need to delete the Network Profile through Azure CLI command like this:
NETWORK_PROFILE_ID=$(az network profile list --resource-group yourResourceGroup --query [0].id --output tsv)
az network profile delete --id $NETWORK_PROFILE_ID -y
After you delete the Network Profile, then you can delete the subnet as you want. For mor details, see Delete network resources.
well, i'd assume your best bet is to try and find the lingering resource and delete it (rest api would work best here, probably). another option is to recreate the ACI with the same name and remove the binding to the network before deleting it.
And your last option would be to contact support ;)
I had the same issue and me help below steps to remove aci subnet and vnet with trash container nic:
1st - find name of problem network profile by command - > az network profile list --query [].name -o tsv
2nd - create resource by terraform -> resource "azurerm_network_profile" "example" with the same network profile name and problem subnet id.
3rd - after terraform successfully create network profile, remove it by -> az network profile delete --id ...(you can find id by az network profile list --query [].id -o tsv)
4th - go to portal and change subnet delegate from container to none, after save I could delete subnet and vnet.
Below is the solution. Sometime trying just delete doesn't work. Follow the below steps and which is tested and worked for me.
NETWORK_PROFILE_ID=$(az network profile list --resource-group yourResourceGroup --query [0].id --output tsv)
az network profile delete --id $NETWORK_PROFILE_ID -y
This is a known issue and Microsoft is working on it. The workaround that worked for me is to update the containerNetworkInterfaceConfigurations property in Network profile properties to an empty list
# Get network profile ID
NETWORK_PROFILE_ID=$(az network profile list --resource-group <reource-group-name> --query [0].id --output tsv)
az resource update --ids $NETWORK_PROFILE_ID --set properties.containerNetworkInterfaceConfigurations=[]
And then deleting it works
az network profile delete --id $NETWORK_PROFILE_ID -y