Get-AzVM

Cmdlet name: Get-AzVM

Module: Az.Compute

Synopsis: Gets one or more virtual machines.

Description: The Get-AzVM cmdlet gets virtual machines in Azure. You can get a specific virtual machine by name or the virtual machines in a resource group. You can also get all virtual machines in a subscription.

SYNOPSIS

Gets one or more virtual machines.

SYNTAX

Get-AzVM
    [-Name ]
    [-ResourceGroupName ]
    [-Status]
    [-VMId ]
    [-DefaultProfile ]
    []

DESCRIPTION

The Get-AzVM cmdlet gets virtual machines in Azure. You can get a specific virtual machine by name or the virtual machines in a resource group. You can also get all virtual machines in a subscription.

PARAMETERS

Name Type Description
-Name System.String Specifies the name of the virtual machine that this cmdlet gets.
-ResourceGroupName System.String Specifies the name of the resource group that contains the virtual machine.
-Status System.Management.Automation.SwitchParameter Gets the status of the virtual machine.
-VMId System.String Specifies the ID of the virtual machine.
-DefaultProfile Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer The credentials, account, tenant, and subscription for the cloud service. By default, this cmdlet uses the authenticated session that is established by the Set-AzContext cmdlet.
-CommonParameters System.Management.Automation.CommonParameters This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, OutVariable. To get the list of the parameters, type Get-Help commonparameter.

EXAMPLES

Example 1: Get all virtual machines in a resource group

This command gets all virtual machines in the specified resource group.

Get-AzVM -ResourceGroupName "RG01"

Example 2: Get a specific virtual machine

This command gets the virtual machine named "MyVM" in the specified resource group.

Get-AzVM -ResourceGroupName "RG01" -Name "MyVM"

Example 3: Get all virtual machines in a subscription

This command gets all virtual machines in the current subscription.

Get-AzVM

Example 4: Get a virtual machine with its status

This command gets the virtual machine named "MyVM" and displays its current status.

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

INPUTS

Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine

You can pipe a virtual machine object to the Get-AzVM cmdlet.

OUTPUTS

Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine

The Get-AzVM cmdlet returns objects that represent virtual machines.