我找到了script使用较旧的 RM Powershell 命令获取最新版本的 Azure 资源提供程序,例如 Microsoft.Compute/availabilitySets 等(也称为类型),并将它们与指定 ARM 模板上的资源进行比较:
Get-Content leanArmTemplate.json |
ConvertFrom-Json |
Select-Object -ExpandProperty resources |
ForEach-Object {
$latestApiVersion = Get-AzureRmResourceProviderLatestApiVersion -Type $_.type
[PsCustomObject]@{
Type = $_.type
UsedApiVersion = $_.apiVersion
LatestVersion = $latestApiVersion
Latest = $_.apiVersion -eq $latestApiVersion
}
}
但是,最新版本的 Get-AzResourceProvider 采用命名空间 (Microsoft.Compute)。 我写了以下内容:
Param (
[string]$FileName = ""
)
$extension = ($FileName -split '\.' | Select-Object -Last 1).ToLower()
if ($FileName -eq "" || $extension -ne "json")
{
Write-Host "Must specifiy an ARM template"
return
}
Get-Content $FileName |
ConvertFrom-Json |
Select-Object -ExpandProperty resources |
ForEach-Object {
$resource = $_
$splitTypes = $resource.type -split '/', 5
$length = $splitTypes.Length
$needed = $length - 1
$splitTypes[1] = ($splitTypes | Select-Object -Last $needed) -join '/'
(Get-AzResourceProvider -ProviderNamespace $splitTypes[0]).ResourceTypes | Where-Object { $_.ResourceTypeName -contains $splitTypes[1] } | ForEach-Object {
[PsCustomObject]@{
Type = $resource.type
UsedApiVersion = $resource.apiVersion
LatestVersion = $_.ApiVersions[0]
Latest = $resource.apiVersion -eq $_.ApiVersions[0]
}
}
}
似乎适用于我当前的模板。有任何改进/明显错误/简化的建议吗?
最佳答案
https://aka.ms/arm-ttk将测试模板中的 apiVersions。
关于azure - 标记 ARM 模板中的过时版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73221451/