Difference between revisions of "Azure/az-cli"

From Ever changing code
Jump to navigation Jump to search
m (Pio2pio moved page Azure Cli to Azure/CLI without leaving a redirect)
Line 2: Line 2:
Note <tt>az</tt> replaced <tt>AzureRM</tt> that is backwards compatible but both shouldn't be installed at the same time. [https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azurermps-6.12.0 Official installation guide] might come here very handy. Otherwise follow quick steps:
Note <tt>az</tt> replaced <tt>AzureRM</tt> that is backwards compatible but both shouldn't be installed at the same time. [https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azurermps-6.12.0 Official installation guide] might come here very handy. Otherwise follow quick steps:


<source lang="PS">
<syntaxhighlightjs lang="PowerShell">
### Install
# Install
$PSVersionTable.PSVersion #check required version PowerShell 5.x or 6.x
C:\> $PSVersionTable.PSVersion #check required version PowerShell 5.x or 6.x
Install-Module -Name Az -AllowClobber #admin rights required
Install-Module -Name Az -AllowClobber #admin rights required
### Sign in
# Sign in
# Import the module into the PowerShell session
# Import the module into the PowerShell session
Import-Module Az
C:\> Import-Module Az
# Connect to Azure with a browser sign in token
# Connect to Azure with a browser sign in token
Connect-AzAccount
C:\> Connect-AzAccount
WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code DUNAAABBB
WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code DUNAAABBB
to authenticate.
to authenticate.
Line 21: Line 21:


# Update module
# Update module
Update-Module -Name Az
C:\> Update-Module -Name Az
</source>
</syntaxhighlightjs>


= Get a list of all subnets =
= Get a list of all subnets =

Revision as of 20:04, 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">

  1. Install

C:\> $PSVersionTable.PSVersion #check required version PowerShell 5.x or 6.x Install-Module -Name Az -AllowClobber #admin rights required

  1. Sign in
  2. Import the module into the PowerShell session

C:\> Import-Module Az

  1. Connect to Azure with a browser sign in token

C:\> Connect-AzAccount 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

  1. Update module

C:\> Update-Module -Name Az </syntaxhighlightjs>

Get a 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

Resources