Module: Az.Compute

Get-AzVMssVM

Gets a virtual machine (VM) from a virtual machine scale set (VMSS).

Syntax

The following are the syntax examples for the Get-AzVMssVM cmdlet.

CmdletBinding

[CmdletBinding()]
param
(
    [Parameter(
        Mandatory = $true,
        Position = 0,
        ValueFromPipeline = $true,
        ValueFromPipelineByPropertyName = $true
    )]
    [string[]] $VMSSVMId,

    [Parameter(
        Mandatory = $true,
        Position = 1
    )]
    [string] $InstanceId,

    [Parameter(
        Mandatory = $true,
        Position = 2
    )]
    [string] $ResourceGroupName
)

NoInput

Get-AzVMssVM
    -InstanceId "6"
    -ResourceGroupName "MyResourceGroup"
    [-VMSSVMId "resourceId"]
    [-DefaultProfile ""]

Parameters

Name Type Description
VMSSVMId String[] The resource IDs of the VMSS VM.
InstanceId String The instance ID of the VMSS VM.
ResourceGroupName String The name of the resource group.
DefaultProfile IAzureContextContainer The Azure context, which is an object that represents the access credentials and settings for a connection to Azure. You can get the context by calling Get-AzContext.

Examples

Example 1: Get all VMs from a VMSS

Get-AzVMssVM -ResourceGroupName "MyResourceGroup" -VMSSName "MyVMSS"

This command gets all virtual machines within the specified virtual machine scale set in the "MyResourceGroup" resource group.

Example 2: Get a specific VM from a VMSS by instance ID

Get-AzVMssVM -ResourceGroupName "MyResourceGroup" -VMSSName "MyVMSS" -InstanceId "3"

This command retrieves the virtual machine with instance ID "3" from the specified virtual machine scale set.

Example 3: Get a specific VM from a VMSS by resource ID

Get-AzVMssVM -VMSSVMId "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/MyVMSS/virtualMachines/5"

This command gets the virtual machine using its full resource ID.

Example 4: Get multiple VMs from a VMSS by instance IDs

Get-AzVMssVM -ResourceGroupName "MyResourceGroup" -VMSSName "MyVMSS" -InstanceId "1", "4"

This command retrieves virtual machines with instance IDs "1" and "4" from the specified virtual machine scale set.

Remarks

The Get-AzVMssVM cmdlet gets a virtual machine (VM) from a virtual machine scale set (VMSS).

This cmdlet can be used to retrieve information about individual VMs within a scale set, such as their status, configuration, and associated data.

You can filter the VMs by specifying the resource group name, VMSS name, or individual VM instance IDs.

Return Value

The cmdlet returns an object representing the virtual machine scale set VM. This object contains properties such as:

  • VmId: The unique identifier of the VM.
  • InstanceId: The instance ID of the VM within the scale set.
  • Name: The name of the VM.
  • ResourceGroupName: The name of the resource group containing the VMSS.
  • ProvisioningState: The provisioning state of the VM.
  • OsType: The operating system type of the VM.
  • ComputerName: The computer name of the VM.
  • PowerState: The power state of the VM (e.g., Running, Stopped).
  • IPAddress: The IP address assigned to the VM.