Category Archives: Azure PowerShell

Microsoft Azure Discovery Series – Azure PowerShell Az module

In this session of Cloud Ranger’s Microsoft Azure Discovery Series, I introduce the upcoming Azure PowerShell Module “Az”. I will start off with what this Az module is and how it is important as it will change how everyone uses Azure PowerShell. I will show how to install this module, use this module, and how to even make your current scripts with this module.

# Check if Azure  ARM modules are installed and what version is installed
Get-Module AzureRM -ListAvailable

# Uninstall all Azure modules (be careful before doing this. I am hoping you are doing this on a dev machine)
Get-Module AzureRM* -ListAvailable | Uninstall-Module

# Install Az PowerShell modules
Install-Module -Name Az

# Connect to the Azure account using the Az module
Add-AzAccount

# Check which subscription you are connected to
Get-AzContext

# Add an Alias to use the old Azure ARM cmdlets or scripts
Enable-AzureRmAlias

Now once you are done testing if you do not want to keep the Az modules then remove them.

# Uninstall all AZ MODULES
Get-Module Az* -ListAvailable | Uninstall-Module

 

Exam 70-533 Module 2 – Lesson 2 (Part 2) – Implementing and managing virtual networks

In this lesson, as a continuation of the previous lesson, I get into details of Azure Virtual Networks and how to implement them in Azure PowerShell and CLI 2.0. I will be primarily using Visual Studio Code as my editor and Azure Cloud Shell to run the PowerShell and CLI commands. Watch my previous module (link below in description) to get started with Azure PowerShell and CLI. Like the previous lesson, this is a jam-packed lesson with loads of hands-on stuff. After explaining some concepts, we go hands-on in building an actual Azure virtual network with two subnets through the Azure PowerShell and Azure CLI. As a bonus I also show how to create virtual machines in Azure PowerShell and CLI.

Azure PowerShell – List all VMs that are using a specific VNet subnet

I recently had a query from someone on how-to list all the VMs in a subscription that are part of a subnet. The following script will do this for you:

$vms = Get-AzureVM

 $tgtSubnet = "Subnet-1"

 foreach($vm in $vms)
 {

   $thisVM = Get-AzureVM -ServiceName $vm.ServiceName –Name $vm.Name

   $thisVMSubnet = Get-AzureSubnet -VM $thisVM

   if ($thisVMSubnet -eq $tgtSubnet)
   {
     $thisVM.Name | Out-File C:\Azure\subnet_VM.txt
   }

 }