简体   繁体   中英

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

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. I can see this information using the Azure portal (under Settings > Properties > SOURCE IMAGE NAME). How can I get the source image name using PowerShell?

You get the source image ID from the operating system disk's properties.

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.

> 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:

> $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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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