繁体   English   中英

如何使用 PowerShell 找到用于创建 Azure VM 的 VM 映像的名称?

[英]How can I find the name of the VM image used to create an Azure VM using PowerShell?

如果我使用 Get-AzureVM(PowerShell cmdlet)来获取正在运行的 VM,那么我返回的字段是

DeploymentName
Name
Label
VM
InstanceStatus
IpAddress
InstanceStateDetails
PowerState
InstanceErrorCode
InstanceFaultDomain
InstanceName
InstanceUpgradeDomain
InstanceSize
HostName
AvailabilitySetName
DNSName
Status
GuestAgentStatus
ResourceExtensionStatusList
PublicIPAddress
PublicIPName
PublicIPDomainNameLabel
PublicIPFqdns
NetworkInterfaces
VirtualNetworkName
ServiceName
OperationDescription
OperationId
OperationStatus

但是,我看不到用于创建 VM 的映像的名称。 我可以使用 Azure 门户(在“设置”>“属性”>“源图像名称”下)查看此信息。 如何使用 PowerShell 获取源图像名称?

您可以从操作系统磁盘的属性中获取源映像 ID。

尝试这个:

$vm = Get-AzureVM -ServiceName serviceName -Name vmName 
$vm.VM.OSVirtualHardDisk

那么你应该得到这个,例如:

HostCaching     : ReadWrite
DiskLabel       : 
DiskName        : multinicdemo-host1-0-201504131546160112
MediaLink       : https://multinicdemo.blob.core.windows.net/vhds/multinicdemo-host1-2015-4-13-17-46-7-664-0.vhd
SourceImageName : a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201503.01-en.us-127GB.vhd
OS              : Windows
IOType          : Standard
ResizedSizeInGB : 
ExtensionData   : 

或者在一行中:

(Get-AzureVM -ServiceName serviceName -Name vmName).VM.OSVirtualHardDisk.SourceImageName

如果您想在不使用 cmd/Powershell 的情况下检查源映像,请执行以下步骤:如何查找正在运行的 VM 映像版本。

> Go to azure portal
> Select the running/stopped VM whose image you want to identify
> Go to export template option
> On the right side of the screen, you will see the template window will open in JSON format.
> Ctrl+F (search) > imageReference > you will get your image version in the template.

在新的“ Az ” Powershell 模块中,您必须检查源图像,如下所示:

> $vm = (Get-AzVM -Name <VM_NAME>)
> $vm.StorageProfile.ImageReference

你应该得到这样的东西:

Publisher    :
Offer        :
Sku          :
Version      :
ExactVersion : 1.0.0
Id           : <RESOURCE_ID_FOR_YOUR_IMAGE>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM