![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to list the Azure VMs from the Availability set using PowerShell?
To list the Azure VMs under the availability set, we can use the command as shown below
Before running the command make sure that you are connected to the Azure Cloud (if not use ConnectAzAccount) and proper azure subscription (Set-AzContext to set the Azure subscription)
$availabilitySetVMs = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySet
To get the total number of Virtual machines in the availability set,
PS C:\> $availabilitySetVMs.VirtualMachinesReferences.id.count
Output
To get all the VM names from the list, we can use the below command.
$VMlist = Get-AzAvailabilitySet -ResourceGroupName MYRESOURCEGROUPAVAILABILITY -Name myAvailabilitySet $i=0 foreach($vm in $VMlist.VirtualMachinesReferences){ "VM{0}: {1}" -f $i,($vm.Id.Split('/'))[-1] $i++ }
Output
Advertisements