Azure powershell and cli

Azure powershell

Install azure module in windows powershell

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Install-Module -Name Az -AllowClobber

To connect to azure account

Connect-AzAccount

To list the subscription

Get-AzSubscription

To list the Resource groups

Get-AzResourceGroup

To create Resource group

New-AzResourceGroup -Name "vignesh-test-ps" -Location 'East US'

To create a virtual machine

New-AzVm -ResourceGroupName "vignesh-test-ps" -Name "ubuntu-test" -Image "UbuntuLTs" -Location "East US" -Size "Standard_B2s"

To delete virtual machine


To delete resource group

Remove-AzResourceGroup -Name "vignesh-test-ps"

Azure cli

To connect to azure account

az login

or

az login --user <myAlias@myCompany.com> -password <myPassword>

To list the subscription

# get the current default subscription using show
az account show --output table

# get the current default subscription using list
az account list --query "[?isDefault]"

# change the active subscription using the subscription name
az account set --subscription "My Demos"

# change the active subscription using the subscription ID
az account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

To list the Resource groups

az group list

To create Resource group

az group create --name vignesh-test-cli --location eastus

To create a virtual machine

az vm create \
    --resource-group vignesh-test-cli \
    --name windows-test \
    --image Win2022AzureEditionCore \
    --public-ip-sku Standard \
    --admin-username azureuser

To delete virtual machine

az vm delete \
    --resource-group vignesh-test-cli \
    --name windows-test \
    --force-deletion none

To delete resource group

az group delete --name vignesh-test-cli