azure - 标记 ARM 模板中的过时版本号

标签 azure powershell azure-resource-manager

我找到了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/

相关文章:

azure - Azure功能监控定价的计算

powershell - 任务计划未执行可通过任务计划程序(Windows10)手动运行的Powershell脚本

git - 之前尝试过错误地将文件夹放入 GitHub

powershell - 为什么我的 Azure Function 没有纵向扩展?

azure - 在每个订阅中使用 azure 策略创建资源组

azure - 将 SQL Server 数据库从 Rackspace 云迁移到 Microsoft Azure

azure - 如何获取 Azure APIM 运行状况检查和详细信息

azure - Azure 搜索基本中是否禁止 OPTIONS 请求?

azure - 当 Azure 应用程序服务(网站)抛出异常时,通过电子邮件通知我的管理员的最佳方式

powershell - 检查Azure资源组是否存在-Azure Powershell