你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Get-AzVM
Gets the properties of a virtual machine.
Syntax
Get-AzVM
[[-ResourceGroupName] <String>]
[[-Name] <String>]
[-Status]
[-UserData]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzVM
[-ResourceGroupName] <String>
[-Name] <String>
[-Status]
[-DisplayHint <DisplayHintType>]
[-UserData]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzVM
-Location <String>
[-Status]
[-UserData]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzVM
[-Status]
-ResourceId <String>
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Get-AzVM cmdlet gets the model view or the instance view of an Azure virtual machine. The model view is the user specified properties of the virtual machine. The instance view is the instance level status of the virtual machine. Specify the Status parameter to get the instance view of a virtual machine instead of the model view which is the default.
Examples
Example 1: Get model properties of the virtual machine named VirtualMachine07
Get-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
ResourceGroupName : ResourceGroup11
Id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ResourceGroup11/providers/M
icrosoft.Compute/virtualMachines/VirtualMachine07
VmId : 00000000-0000-0000-0000-000000000000
Name : VirtualMachine07
Type : Microsoft.Compute/virtualMachines
Location : eastus
Tags : {"creationSource":"acs-VirtualMachine07"}
AvailabilitySetReference : {Id}
DiagnosticsProfile : {BootDiagnostics}
Extensions : {linuxdiagnostic, waitforleader}
HardwareProfile : {VmSize}
NetworkProfile : {NetworkInterfaces}
OSProfile : {ComputerName, AdminUsername, LinuxConfiguration, Secrets}
ProvisioningState : Succeeded
StorageProfile : {ImageReference, OsDisk, DataDisks}
This command gets the model view and instance view properties of the virtual machine named VirtualMachine07.
Example 2: Get instance view properties
Get-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07" -Status
ResourceGroupName : ResourceGroup11
Name : VirtualMachine07
Disks[0] :
Name : VirtualMachine07-osdisk
Statuses[0] :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Time : 3/1/2019 12:59:30 AM
Extensions[0] :
Name : linuxdiagnostic
Type : Microsoft.OSTCExtensions.LinuxDiagnostic
TypeHandlerVersion : 2.3.9029
Statuses[0] :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message : Invalid config settings given: Empty storageAccountName. Install will proceed, but enable
can't proceed, in which case it's still considered a success as it's an external error.
Extensions[1] :
Name : waitforleader
Type : Microsoft.OSTCExtensions.CustomScriptForLinux
TypeHandlerVersion : 1.5.4
Statuses[0] :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message : Command is finished.
---stdout---
waiting for leader.mesos
waiting for leader.mesos
waiting for leader.mesos
waiting for leader.mesos
waiting for leader.mesos
waiting for leader.mesos
PING leader.mesos (xxx.xx.x.x) 56(84) bytes of data.
64 bytes from xxx.xx.x.x: icmp_seq=1 ttl=64 time=0.022 ms
--- leader.mesos ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.022/0.022/0.022/0.000 ms
leader.mesos up
---errout---
ping: unknown host leader.mesos
ping: unknown host leader.mesos
ping: unknown host leader.mesos
ping: unknown host leader.mesos
ping: unknown host leader.mesos
ping: unknown host leader.mesos
PlatformFaultDomain : 0
PlatformUpdateDomain : 0
VMAgent :
VmAgentVersion : 2.2.37
ExtensionHandlers[0] :
Type : Microsoft.OSTCExtensions.LinuxDiagnostic
TypeHandlerVersion : 2.3.9029
Status :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Ready
Message : Plugin enabled
ExtensionHandlers[1] :
Type : Microsoft.OSTCExtensions.CustomScriptForLinux
TypeHandlerVersion : 1.5.4
Status :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Ready
Message : Plugin enabled
Statuses[0] :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Ready
Message : Guest Agent is running
Time : 3/1/2019 2:04:12 AM
Statuses[0] :
Code : ProvisioningState/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Time : 3/1/2019 1:01:57 AM
Statuses[1] :
Code : PowerState/running
Level : Info
DisplayStatus : VM running
This command gets properties of the virtual machine named VirtualMachine07. This command specifies the Status parameter. Therefore, the command gets only the instance view properties.
Example 3: Get properties for all virtual machines in a resource group
Get-AzVM -ResourceGroupName "ResourceGroup11"
ResourceGroupName Name Location VmSize OsType NIC
----------------- ---- -------- ------ ------ ---
ResourceGroup11 test1 eastus Standard_DS1_v2 Windows test1
ResourceGroup11 test2 westus Standard_DS1_v2 Windows test2
ResourceGroup11 test3 eastus Standard_DS1_v2 Windows test3
This command gets properties for all the virtual machines in the resource group named ResourceGroup11.
Example 4: Get all virtual machines in your subscription
Get-AzVM
ResourceGroupName Name Location VmSize OsType NIC
----------------- ---- -------- ------ ------ ---
TEST1 test1 eastus Standard_DS1_v2 Windows test1
TEST1 test2 westus Standard_DS1_v2 Windows test2
TEST1 test3 eastus Standard_DS1_v2 Windows test3
TEST2 test4 westus Standard_DS1_v2 Windows test4
TEST2 test5 eastus Standard_DS1_v2 Windows test5
This command gets all the virtual machines in your subscription.
Example 5: Get all virtual machines in the location.
Get-AzVM -Location "westus"
ResourceGroupName Name Location VmSize OsType NIC
----------------- ---- -------- ------ ------ ---
TEST1 test2 westus Standard_DS1_v2 Windows test2
TEST2 test4 westus Standard_DS1_v2 Windows test4
This command gets all the virtual machines in West US region.
Example 6: Get all virtual machines using filtering
Get-AzVM -Name test*
ResourceGroupName Name Location VmSize OsType NIC
----------------- ---- -------- ------ ------ ---
TEST1 test1 eastus Standard_DS1_v2 Windows test1
TEST1 test2 westus Standard_DS1_v2 Windows test2
TEST1 test3 eastus Standard_DS1_v2 Windows test3
TEST2 test4 westus Standard_DS1_v2 Windows test4
TEST2 test5 eastus Standard_DS1_v2 Windows test5
This command gets all virtual machines with names start with "test"
Example 7: Get VM with UserData value
Get-AzVM -ResourceGroupName <Resource Group Name> -Name <VM Name> -UserData;
ResourceGroupName : <>
Id : /subscriptions/<Subscription Id>/resourceGroups/<Resource Group Name>/providers/Microsoft
.Compute/virtualMachines/<VM Name>
VmId : <VM Id>
Name : <VM Name>
Type : Microsoft.Compute/virtualMachines
Location : eastus
Tags :
{"azsecpack":"nonprod","platformsettings.host_environment.service.platform_optedin_for_rootcerts":"true"}
Extensions : {Microsoft.Azure.Geneva.GenevaMonitoring,
Microsoft.Azure.Security.AntimalwareSignature.AntimalwareConfiguration}
HardwareProfile : {VmSize}
NetworkProfile : {NetworkInterfaces}
OSProfile : {ComputerName, AdminUsername, WindowsConfiguration, Secrets, AllowExtensionOperations,
RequireGuestProvisionSignal}
ProvisioningState : Succeeded
StorageProfile : {ImageReference, OsDisk, DataDisks}
UserData : bm90IGVuY29kZWQ=
The UserData value must always be Base64 encoded. This command assumes you have already created a VM with a UserData value.
Parameters
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.
Type: | IAzureContextContainer |
Aliases: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DisplayHint
Determines how the virtual machine object is displayed. Valid values are: -- Compact: displays only top level properties -- Expand: displays all properties in all levels
Type: | DisplayHintType |
Accepted values: | Compact, Expand |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Location
Specifies a location for the virtual machines to list.
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Name
Specifies the name of the virtual machine to get.
Type: | String |
Aliases: | ResourceName, VMName |
Position: | 1 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-ResourceGroupName
Specifies the name of a resource group.
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-ResourceId
Id of the VM
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Status
Indicates that this cmdlet gets only the instance view of the virtual machine.
Type: | SwitchParameter |
Position: | 2 |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-UserData
UserData for the VM, which will be base-64 encoded. Customer should not pass any secrets in here.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |