Azure Classroom Series – 19/Jul/2020

Azure VNet with Powershell

  • CmdLets:
    • Will be in the form of <verb>-<noun> -arg1 value-n … -argn value-n
  • Modules:
    • Collection of Cmdlets and Functions
  • Azure Powershell commandlets are also made available as Module
Install-Module -Name Az -AllowClobber -Scope CurrentUser
  • Noun in the case of Azure Powershell will have prefix of Az

  • Use Connect-AzAccount to login into azure so that powershell can use credentials similar to az login

How to Search for Powershell Cmdlet for Azure

  • Navigate to documents over here and search in reference section for the services Preview Preview

  • Other Way:

    • Let assume we are searching for Resource group
    Get-Command '*-AzResourceGroup*'


    • Now if we want to create a resource group
    Get-Help -Online New-AzResourceGroup


  • Developer Environment:

    • Create a newfolder with new file <filename>.ps1
    • Open this folder in visual studio code
    • Ensure Powershell extension is installed Preview
  • Now lets create a ntier vnet in some region with 4 subnets using Azure Powershell

# Create a resource group
$resg = New-AzResourceGroup -Name 'fromps' -Location 'centralus'

# Create subnet references
$websubnet = New-AzVirtualNetworkSubnetConfig -Name 'web' -AddressPrefix '' 

$appsubnet = New-AzVirtualNetworkSubnetConfig -Name 'app' -AddressPrefix ''

$dbsubnet = New-AzVirtualNetworkSubnetConfig -Name 'db' -AddressPrefix ''

$managementsubnet = New-AzVirtualNetworkSubnetConfig -Name 'management' -AddressPrefix ''

# Create a virtual network
$vnet = New-AzVirtualNetwork -Name 'ntier' -ResourceGroupName $resg.ResourceGroupName -Location $resg.Location -AddressPrefix '' -Subnet $websubnet,$appsubnet,$dbsubnet,$managementsubnet

  • Execute the above commands in the Powershell Terminal and navigate to azure portal to view vnet and the subnets in it Preview

  • To Get info about azure vnet in Powershell Execute verb Get based cmd lets Preview

  • Extend this virtual network by creating a network security group which allows 22 and 80 port for internet, all for virtual network and rest denied

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin