Get-AzVM
取得虛擬機器的屬性。
語法
DefaultParamSet (預設值)
Get-AzVM
[[-ResourceGroupName] <String>]
[[-Name] <String>]
[-Status]
[-UserData]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
GetVirtualMachineInResourceGroupParamSet
Get-AzVM
[-ResourceGroupName] <String>
[-Name] <String>
[-Status]
[-DisplayHint <DisplayHintType>]
[-UserData]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
ListLocationVirtualMachinesParamSet
Get-AzVM
-Location <String>
[-Status]
[-UserData]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
GetVirtualMachineById
Get-AzVM
-ResourceId <String>
[-Status]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
Get-AzVM Cmdlet 會取得 Azure 虛擬機器的模型檢視或執行個體檢視。 模型檢視是使用者指定的虛擬機器屬性。 執行個體檢視是虛擬機器的執行個體層級狀態。 指定 Status 參數以取得虛擬機器的執行個體檢視,而不是預設的模型檢視。
範例
範例 1:取得名為 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}
此命令會取得名為 VirtualMachine07 之虛擬機器的模型檢視和實例檢視屬性。
範例 2:取得執行個體檢視屬性
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
此命令會取得名為 VirtualMachine07 的虛擬機器屬性。 此指令指定 Status 參數。 因此,指令只會取得實例檢視內容。
範例 3:取得資源群組中所有虛擬機器的屬性
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
此命令會取得名為 ResourceGroup11 之資源群組中所有虛擬機器的屬性。
範例 4:取得訂用帳戶中的所有虛擬機器
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
此命令會取得訂用帳戶中的所有虛擬機器。
範例 5:取得該位置中的所有虛擬機器。
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
此命令會取得美國西部區域中的所有虛擬機器。
範例 6:使用篩選取得所有虛擬機器
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
此命令會取得名稱以「test」開頭的所有虛擬機器
範例 7:取得具有 UserData 值的 VM
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=
UserData 值必須一律以 Base64 編碼。 此命令假設您已建立具有 UserData 值的 VM。
參數
-DefaultProfile
用於與 azure 通訊的認證、帳戶、租用戶和訂用帳戶。
參數屬性
| 類型: | IAzureContextContainer |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | AzContext, AzureRmContext, AzureCredential |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-DisplayHint
決定虛擬機器物件的顯示方式。 有效值為: -- 壓縮:僅顯示最上層內容 -- 展開:顯示所有層次中的所有內容
參數屬性
| 類型: | DisplayHintType |
| 預設值: | None |
| 接受的值: | Compact, Expand |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
GetVirtualMachineInResourceGroupParamSet
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Location
指定要列出的虛擬機器位置。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
ListLocationVirtualMachinesParamSet
| Position: | Named |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Name
指定要取得的虛擬機器名稱。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
| 別名: | 資源名稱, VMName |
參數集
DefaultParamSet
| Position: | 1 |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-ResourceGroupName
指定資源群組的名稱。
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
DefaultParamSet
| Position: | 0 |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-ResourceId
VM 的標識碼
參數屬性
| 類型: | String |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
GetVirtualMachineById
| Position: | Named |
| 必要: | True |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-Status
表示此 Cmdlet 只會取得虛擬機器的執行個體檢視。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | 2 |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-UserData
UserData,將以 base-64 編碼。 客戶不應在此傳遞任何秘密。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
DefaultParamSet
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
GetVirtualMachineInResourceGroupParamSet
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
ListLocationVirtualMachinesParamSet
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
CommonParameters
此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。