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
    Get-Process
    
  • 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
Get-AzResourceGroup
Create-AzVnet

  • 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*'
    

    Preview

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

    Preview

  • 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 '172.16.0.0/24' 

$appsubnet = New-AzVirtualNetworkSubnetConfig -Name 'app' -AddressPrefix '172.16.1.0/24'

$dbsubnet = New-AzVirtualNetworkSubnetConfig -Name 'db' -AddressPrefix '172.16.2.0/24'

$managementsubnet = New-AzVirtualNetworkSubnetConfig -Name 'management' -AddressPrefix '172.16.3.0/24'

# Create a virtual network
$vnet = New-AzVirtualNetwork -Name 'ntier' -ResourceGroupName $resg.ResourceGroupName -Location $resg.Location -AddressPrefix '172.16.0.0/16' -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