如何通过 REST API、Powershell 或 Azure CLI 提取 azure 资源模板格式

How to extract azure resource template format either via REST API, Powershell or Azure CLI

有没有办法以编程方式提取 azure 资源模板格式(REST API、Powershell、Azure CLI)?

最终结果应该与此处呈现的 JSON 类似,其中包括数据类型等: https://docs.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/vaults?tabs=json

最好也能 select API-版本: https://docs.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/2015-06-01/vaults?tabs=json

我试过使用 az provider 和扩展属性,但属性总是空的。

az provider show -n Microsoft.KeyVault --expand resourceTypes/properties

az resource 似乎只能使用现有资源。

如果您只想提取 Azure ARM 模板格式,请尝试以下 PowerShell:

$webRequest = Invoke-WebRequest "https://docs.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/2019-09-01/vaults"
 
$webRequest.ParsedHTML.getElementsByClassName("lang-json") | % innerHTML

它在 5.0 下工作: