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
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:
Full output:
The
Get-AzVMImage
command does not produce the expected output. You want to see aPSVirtualMachineImageDetail
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 typePSVirtualMachineImage
andPSVirtualMachineImageDetail
, as per the documentation. ThePSVirtualMachineImageDetail
object contains detailed information about the VM image, including properties likeOSDiskImage
.PowerShell output can be very verbose and hide the details you need. Inspect the output carefully.
Powershell script:
Output: