skip to Main Content

Im trying to fetch the detailed information from a azure VM Image but the information doesnt seem to be there.

$location = "swedencentral"
$publisher = "MicrosoftSQLServer" 

#Get all offers for selected publisher
$Alloffers = @(Get-AzVMImageOffer -Location $location -PublisherName $publisher | Select-Object -ExpandProperty Offer)

#Get all images for all skus of all ofers for the selected publisher
foreach ($Offer in $Alloffers) {
    $Allskus = (Get-AzVMImageSku -Location $location -PublisherName $publisher -Offer $offer | Select-Object  -ExpandProperty Skus)
    
    foreach ($sku in $Allskus) {
        $images += @(Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version latest)
     }
}

$images

According to documentation Get-AzVMImage should output PSVirtualMachineImage and PSVirtualMachineImageDetail but the result suggest that only PSVirtualMachineImage is outputed.

https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azvmimage?view=azps-11.1.0

Im I missing something or how can I with PowerShell get the detailed information from an Azure VM Image, specifically I want the Name and the OSDiskImage information.

2

Answers


  1. When using -Version latest, I notice that only partial details are returned for the image.

    When using a specific version Id, more details are returned. Here is example output:

    $temp = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version latest
    $imageFullDetails = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version $temp.Version
    

    Full output:

    PS C:WINDOWSsystem32> $temp = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version latest
    PS C:WINDOWSsystem32> $temp
    
    Version           Skus               Offer         PublisherName          Location  Id
    -------           ----               -----         -------------          --------  --
    9600.21620.231004 2012-R2-Datacenter windowsserver MicrosoftWindowsServer centralus /Subscriptions/b54f6425-8460-401d-bbd4-0e6ff231ed16/Providers/Microsoft.Compute/Locations/centralus/Publishers/MicrosoftWindowsServer/ArtifactTypes/VMImage/Offers/windowsserver/Skus/2012-R2-Data...
    
    
    PS C:WINDOWSsystem32> $imageFullDetails = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version $temp.Version
    PS C:WINDOWSsystem32> $imageFullDetails
    
    
    Id                     : /Subscriptions/b54f6425-8460-401d-bbd4-0e6ff231ed16/Providers/Microsoft.Compute/Locations/centralus/Publishers/MicrosoftWindowsServer/ArtifactTypes/VMImage/Offers/windowsserver/Skus/2012-R2-Datacenter/Versions/9600.21620.231004
    Location               : centralus
    PublisherName          : MicrosoftWindowsServer
    Offer                  : windowsserver
    Skus                   : 2012-R2-Datacenter
    Version                : 9600.21620.231004
    FilterExpression       :
    Name                   : 9600.21620.231004
    HyperVGeneration       : V1
    OSDiskImage            : {
                               "operatingSystem": "Windows"
                             }
    PurchasePlan           : null
    DataDiskImages         : []
    ImageDeprecationStatus : {
                               "imageState": "Active",
                               "scheduledDeprecationTime": null,
                               "alternativeOption": null
                             }
    
    
    
    PS C:WINDOWSsystem32>
    
    Login or Signup to reply.
  2. I tired to use Get-AzVMImage to fetch PSVirtualMachineImageDetail and I was able to provision the requirement successfully.

    The Get-AzVMImage command does not produce the expected output. You want to see a PSVirtualMachineImageDetail object that contains detailed information, such as the Name and OSDiskImage, of the virtual machine image.

    The Get-AzVMImage cmdlet is indeed supposed to return objects of type PSVirtualMachineImage and PSVirtualMachineImageDetail, as per the documentation. The PSVirtualMachineImageDetail object contains detailed information about the VM image, including properties like OSDiskImage.

    PowerShell output can be very verbose and hide the details you need. Inspect the output carefully.

    Powershell script:

    $images = Get-AzImage
    
    if ($images -ne $null) {
        foreach ($image in $images) {
            $output = New-Object PSObject -Property @{
                Name = $image.Name
                ResourceGroupName = $image.ResourceGroupName
                Location = $image.Location
                OSDiskImage = $image.StorageProfile.OsDisk
                DataDisks = $image.StorageProfile.DataDisks | ForEach-Object {
                    @{
                        Lun = $_.Lun
                        BlobUri = $_.BlobUri
                        Caching = $_.Caching
                        SizeGB = $_.DiskSizeGB
                    }
                }
                Tags = $image.Tags
            }
            $output | Format-List
        }
    } else {
        Write-Host "No images found in the subscription."
    }
    

    Output:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search