【问题标题】:How can I find the name of the VM image used to create an Azure VM using PowerShell?如何找到用于使用 PowerShell 创建 Azure VM 的 VM 映像的名称?
【发布时间】:2015-12-02 13:37:36
【问题描述】:

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

【问题讨论】:

    标签: azure azure-vm-role


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案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 映像不同的操作系统映像。我认为最初的问题是在寻找这个。
        • 完美,这很难找到!是否也可以在门户中使用?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-16
        • 1970-01-01
        相关资源
        最近更新 更多