← Compute Cmdlets Parameters | Examples | Related Articles

Get-AzVM

This article describes the Get-AzVM cmdlet and how to use it to retrieve virtual machines (VMs) in Azure.

SYNOPSIS

Gets virtual machines.

SYNTAX

Get-AzVM [-Name ] [-ResourceGroupName ] [-Status] [-DisplayHint ] []
Get-AzVM [-ResourceGroupName ] -VirtualMachineId []
Get-AzVM [-SubscriptionId ] [-VirtualMachineScaleSetVMId ] []
Get-AzVM [-VirtualMachineScaleSetId ] [-VirtualMachineScaleSetVM ] []
Get-AzVM [-VirtualMachineScaleSetVMId ] []

DESCRIPTION

The Get-AzVM cmdlet retrieves information about one or more virtual machines (VMs) in Azure. You can specify the VMs to retrieve by name, resource group, or VM ID.

By default, Get-AzVM retrieves basic information about the VM. You can use the -Status parameter to retrieve the current running status of the VM.

PARAMETERS

Parameter Type Description
-Name String Specifies the name of the VM to retrieve.
-ResourceGroupName String Specifies the name of the resource group that contains the VM.
-Status Switch Retrieves the running status of the VM.
-DisplayHint Microsoft.Azure.Commands.Compute.Models.DisplayHint Specifies the format in which to display the VM. Possible values are 'ComputeReservation', 'BareMetalInstance', 'VirtualMachine'.
-VirtualMachineId String Specifies the ID of the VM.
-SubscriptionId String Specifies the ID of the Azure subscription.
-VirtualMachineScaleSetVMId String Specifies the ID of a VM within a Virtual Machine Scale Set.
-VirtualMachineScaleSetId String Specifies the ID of the Virtual Machine Scale Set.
-VirtualMachineScaleSetVM String Specifies the name of a VM within a Virtual Machine Scale Set.
-CommonParameters System.Management.Automation.Language.CommandMetadata Common cmdlets such as -Verbose, -Debug, -ErrorAction, -WarningAction, -InformationAction, -OutVariable.

EXAMPLES

Example 1: Get all VMs in a resource group

This command retrieves all VMs in the specified resource group.

Get-AzVM -ResourceGroupName "MyResourceGroup"

Example 2: Get a specific VM

This command retrieves a specific VM named "MyVM" in the "MyResourceGroup" resource group.

Get-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM"

Example 3: Get a VM and its status

This command retrieves a specific VM and its current running status.

Get-AzVM -ResourceGroupName "MyResourceGroup" -Name "MyVM" -Status

Example 4: Get all VMs in a subscription

This command retrieves all VMs across all resource groups in the current subscription.

Get-AzVM