我试图从天蓝色的虚拟机映像中获取详细信息,但该信息似乎不存在。
$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
根据文档 Get-AzVMImage 应该输出 PSVirtualMachineImage 和 PSVirtualMachineImageDetail,但结果表明仅输出 PSVirtualMachineImage。
https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azvmimage?view=azps-11.1.0
我错过了一些东西,或者如何使用 PowerShell 从 Azure VM 映像获取详细信息,特别是我想要名称和 OSDiskImage 信息。
使用
-Version latest
时,我注意到仅返回图像的部分细节。
使用特定版本 ID 时,会返回更多详细信息。这是示例输出:
$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
完整输出:
PS C:\WINDOWS\system32> $temp = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version latest
PS C:\WINDOWS\system32> $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:\WINDOWS\system32> $imageFullDetails = Get-AzVMImage -Location $location -PublisherName $publisher -Offer $offer -Skus $sku -Version $temp.Version
PS C:\WINDOWS\system32> $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:\WINDOWS\system32>