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

6
如果我使用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获取源映像名称?

3个回答

10

如果您想在不使用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.

7

您可以从操作系统磁盘属性中获取源映像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

3
在新的“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>

这个答案是正确的。被接受的答案提供了操作系统镜像,可能与Azure镜像不同。我认为原问题就是在寻找这个。 - joelforsyth
太好了,这个很难找到!它在门户网站上也可以找到吗? - iteal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接