How to retrieve the Azure VM resource group using PowerShell?


To retrieve the azure VM resource group using PowerShell, we first need to retrieve the Azure VM details using Get-AZVm and then we can use its property called ResourceGroup.

Before getting the details of the Azure VM, make sure that you are connected to the Azure Account using the Connect-AzAccount command.

In this example, we are going to retrieve the Azure VM named TestMachine2k16 to retrieve the VM details.

$azvm = Get-AzVM -Name TestMachine2k16

To get the resource group name, use its property ResourceGroupName.

PS C:\> $azvm.ResourceGroupName
ANSIBLETESTRG

Updated on: 17-May-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements