简体   繁体   English

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

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

If I use Get-AzureVM (PowerShell cmdlet) to fetch a running VM then the fields I get back are如果我使用 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

However I cannot see the name of the image used to create the VM.但是,我看不到用于创建 VM 的映像的名称。 I can see this information using the Azure portal (under Settings > Properties > SOURCE IMAGE NAME).我可以使用 Azure 门户(在“设置”>“属性”>“源图像名称”下)查看此信息。 How can I get the source image name using PowerShell?如何使用 PowerShell 获取源图像名称?

You get the source image ID from the operating system disk's properties.您可以从操作系统磁盘的属性中获取源映像 ID。

Try this:尝试这个:

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

Then you should get this for example:那么你应该得到这个,例如:

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   : 

Or in one line:或者在一行中:

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

If you want to check the source image without using cmd/Powershell, then follow these steps: How to find the running VM image version.如果您想在不使用 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.

In the new ' Az ' Powershell module you have to check for source image as below:在新的“ Az ” Powershell 模块中,您必须检查源图像,如下所示:

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

You should get something like this:你应该得到这样的东西:

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