How to retrieve the Azure VM resource group using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

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
raja
Published on 17-May-2021 12:03:11
Advertisements