Difference between revisions of "Azure/az-cli"
Line 23: | Line 23: | ||
</syntaxhighlightjs> | </syntaxhighlightjs> | ||
= | = List of Vnets = | ||
<source lang="bash"> | |||
$ az network vnet list -o table | |||
# List of VNETs within resource group | |||
$ az network vnet list --resource-group infra_rg -o tsv | cut -f9 | |||
</source> | |||
= List of all subnets = | |||
<source lang="bash"> | <source lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
Line 32: | Line 38: | ||
done | done | ||
done | done | ||
</source> | |||
= List of SQL servers = | |||
<source lang="bash"> | |||
# List of Ms.SQL servers | |||
az sql server list --resource-group infra-euw1 -o tsv | cut -f1,6-10,12-13 | |||
# List all database servers | |||
for AzureResourceGroup in $(az group list -o tsv | cut -f4); do | |||
echo "### $VNET ResourceGroup: $AzureResourceGroup" | |||
az sql server list --resource-group $AzureResourceGroup -o tsv | cut -f1,6-10,12-13 | |||
done | |||
#List all databases | |||
for AzureResourceGroup in $(az group list -o tsv | cut -f4); do | |||
for DbServer in $(az sql server list --resource-group $AzureResourceGroup -o tsv | cut -f1,6-10,12-13); do | |||
echo "### Dbserver: $DbServer, ResourceGroup: $AzureResourceGroup" | |||
az sql db list --resource-group $AzureResourceGroup --server $DbServer | |||
done | |||
done | |||
az resource list -o table --query "[?type=='Microsoft.DBforMySQL/servers'].{name:name, group:resourceGroup}" | |||
az resource list -o table | grep 'Microsoft.DBforMySQL/servers' | |||
az resource list -o table | grep -i 'sql' | sort -k4 | |||
</source> | |||
= List of Virtual Gateways = | |||
<source lang="bash"> | |||
# List all vpn virtual gateways | |||
for AzureResourceGroup in $(az group list -o tsv | cut -f4); do | |||
echo "### $VNET ResourceGroup: $AzureResourceGroup" | |||
az network vnet-gateway list -g $AzureResourceGroup -o table | grep -ve '---' | |||
done | |||
</source> | |||
= List scale sets = | |||
<source lang="bash"> | |||
### VMScaleSets | |||
# List VMSS | |||
az vmss list --resource-group client1 -o table | |||
Name ResourceGroup Location Zones Capacity Overprovision UpgradePolicy | |||
----------------------- --------------- ---------- ------- ---------- --------------- --------------- | |||
client1_external_vmss client1 westeurope 1 2 3 2 True Manual | |||
client1_internal_vmss client1 westeurope 1 2 3 1 True Manual | |||
client1_worker_vmss client1 westeurope 1 2 3 1 True Manual | |||
# List VMSS instances | |||
az vmss list-instances --resource-group client1 --name client1_external_vmss -o table | |||
az vmss nic list -g client1 --vmss-name client1_external_vmss --query [].{ip:ipConfigurations[0].privateIpAddress} -o tsv | |||
# Get VMs ip addresses in VMSS sets | |||
$ cat > list-all-vmss-ips.sh <<'EOF' | |||
#!/bin/bash | |||
for AzureResourceGroup in $(az group list -o tsv | cut -f4) | |||
do | |||
for vmss in $(az vmss list --resource-group $AzureResourceGroup -o tsv | cut -f4) | |||
do | |||
echo "### $VNET ResourceGroup: $AzureResourceGroup ScaleSet: $vmss" | |||
az vmss nic list -g $AzureResourceGroup --vmss-name $vmss --query [].{ip:ipConfigurations[0].privateIpAddress} -o tsv | |||
done | |||
done | |||
EOF | |||
</source> | </source> | ||
Revision as of 20:24, 2 January 2019
Install az PowerShell module
Note az replaced AzureRM that is backwards compatible but both shouldn't be installed at the same time. Official installation guide might come here very handy. Otherwise follow quick steps:
<syntaxhighlightjs lang="PowerShell">
- Install
C:\> $PSVersionTable.PSVersion #check required version PowerShell 5.x or 6.x C:\> Install-Module -Name Az -AllowClobber #admin rights required
- Sign in
C:\> Import-Module Az # Import the module into the PowerShell session C:\> Connect-AzAccount # Connect to Azure with a browser sign in token WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code DUNAAABBB to authenticate.
Account : john@example.com SubscriptionName : Microsoft Azure Sponsorship SubscriptionId : aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee TenantId : bbbbbbbb-cccc-dddd-eeee-ffffffffffff Environment : AzureCloud
- Update module
C:\> Update-Module -Name Az </syntaxhighlightjs>
List of Vnets
$ az network vnet list -o table # List of VNETs within resource group $ az network vnet list --resource-group infra_rg -o tsv | cut -f9
List of all subnets
#!/bin/bash for ResourceGroup in $(az group list -o tsv | cut -f4); do for VNET in $(az network vnet list --resource-group $ResourceGroup -o tsv | cut -f9); do echo "### ResourceGroup: $ResourceGroup VNET: $VNET" az network vnet subnet list --resource-group $ResourceGroup --vnet-name $VNET -o tsv | cut -f1,9,13 | column -t done done
List of SQL servers
# List of Ms.SQL servers az sql server list --resource-group infra-euw1 -o tsv | cut -f1,6-10,12-13 # List all database servers for AzureResourceGroup in $(az group list -o tsv | cut -f4); do echo "### $VNET ResourceGroup: $AzureResourceGroup" az sql server list --resource-group $AzureResourceGroup -o tsv | cut -f1,6-10,12-13 done #List all databases for AzureResourceGroup in $(az group list -o tsv | cut -f4); do for DbServer in $(az sql server list --resource-group $AzureResourceGroup -o tsv | cut -f1,6-10,12-13); do echo "### Dbserver: $DbServer, ResourceGroup: $AzureResourceGroup" az sql db list --resource-group $AzureResourceGroup --server $DbServer done done az resource list -o table --query "[?type=='Microsoft.DBforMySQL/servers'].{name:name, group:resourceGroup}" az resource list -o table | grep 'Microsoft.DBforMySQL/servers' az resource list -o table | grep -i 'sql' | sort -k4
List of Virtual Gateways
# List all vpn virtual gateways for AzureResourceGroup in $(az group list -o tsv | cut -f4); do echo "### $VNET ResourceGroup: $AzureResourceGroup" az network vnet-gateway list -g $AzureResourceGroup -o table | grep -ve '---' done
List scale sets
### VMScaleSets # List VMSS az vmss list --resource-group client1 -o table Name ResourceGroup Location Zones Capacity Overprovision UpgradePolicy ----------------------- --------------- ---------- ------- ---------- --------------- --------------- client1_external_vmss client1 westeurope 1 2 3 2 True Manual client1_internal_vmss client1 westeurope 1 2 3 1 True Manual client1_worker_vmss client1 westeurope 1 2 3 1 True Manual # List VMSS instances az vmss list-instances --resource-group client1 --name client1_external_vmss -o table az vmss nic list -g client1 --vmss-name client1_external_vmss --query [].{ip:ipConfigurations[0].privateIpAddress} -o tsv # Get VMs ip addresses in VMSS sets $ cat > list-all-vmss-ips.sh <<'EOF' #!/bin/bash for AzureResourceGroup in $(az group list -o tsv | cut -f4) do for vmss in $(az vmss list --resource-group $AzureResourceGroup -o tsv | cut -f4) do echo "### $VNET ResourceGroup: $AzureResourceGroup ScaleSet: $vmss" az vmss nic list -g $AzureResourceGroup --vmss-name $vmss --query [].{ip:ipConfigurations[0].privateIpAddress} -o tsv done done EOF