是否可以使用 PowerShell 获取 Azure 订阅优惠或 offerId?
It is possible to get the Azure Subscription offer, or offerId with PowerShell?
是否可以使用 Powershell 获取 Azure 订阅优惠或 offerId?通过门户,这将是订阅 -> 属性 -> 报价或报价 ID?
找了半天没看到
谢谢,
取决于你需要它做什么。通过 PS 脚本获取 OfferTypes 毫无意义,因为您不会像这样创建新订阅。这个过程比这更复杂。不过,如果您只需要一个列表,可以在 MS 网站上找到:
https://azure.microsoft.com/en-us/support/legal/offer-details/
不幸的是,我认为这是不可能的。我认为为您的问题找到解决方案是明智的。
也许您可以添加请求以在将来添加此功能:
https://github.com/Azure/azure-docs-powershell/blob/master/azuresmps-4.0.0/AzureRM.Profile/Get-AzureRmSubscription.md
可以通过非官方方式获取 Azure 门户本身使用的优惠 ID。我用我的订阅测试了它并且它有效。它可能会导致特定优惠 ID 出现问题。请对此提供反馈。
这些是必需的步骤:
获取 Bearer 认证令牌
Assemble 一个 POST REST 调用
- URL: https://s2.billing.ext.azure.com/api/Billing/Subscription/Subscription
- Headers:使用您的 Bearer 令牌添加授权 header(授权:Bearer ej...)
- 请求Body类型:application/json
- 请求Body内容:
{
"subscriptionId": "########-####-####-####-############"
}
结果如下所示:
{
"accountInfo": {
"userRole": 6,
"billingSystemType": 2,
"isAccountAdmin": true,
"isTokenMatch": false,
"locale": "en-US",
"currency": "EUR",
"countryCode": "DE",
"accountAdminEmail": "****@****.com",
"commerceAccountId": "########-####-####-####-############",
"currencyMigrationInfo": null,
"displaySpecifiedRole": false
},
"essentials": {
"offerId": "MS-AZR-0063P",
"roles": {
"2": null,
"4": {
"isDirectCancel": true
},
"5": null
},
"freeMetersEndDate": null,
"provisioningStatus": 1,
"hasPendingTransfer": false
}
}
现在可以使用 Resource Graph Explorer 通过类似于以下的查询从门户网站完成此操作:
resourcecontainers
| where type == "microsoft.resources/subscriptions"
| project name, properties.subscriptionPolicies.quotaId
没有,但是已经有一个功能请求,please vote for it。
有一种官方方法可以使用 Azure REST API 获取优惠 ID。确保使用 API 版本作为 api-version=2019-10-01
您可以run\try点击下方url试试:
https://docs.microsoft.com/en-us/rest/api/consumption/usagedetails/list#code-try-0
当然,您需要使用您的 Azure 用户 ID 和密码登录 try\test。
您将收到如下所示的响应,其中包含报价 ID:
更多详细信息,请参阅使用详情-列表API:https://docs.microsoft.com/en-us/rest/api/consumption/usagedetails/list。
注意:这不是 PowerShell 方式,但您可以使用 PowerShell/curl 调用 REST Api。参考https://mauridb.medium.com/calling-azure-rest-api-via-curl-eb10a06127
是否可以使用 Powershell 获取 Azure 订阅优惠或 offerId?通过门户,这将是订阅 -> 属性 -> 报价或报价 ID?
找了半天没看到
谢谢,
取决于你需要它做什么。通过 PS 脚本获取 OfferTypes 毫无意义,因为您不会像这样创建新订阅。这个过程比这更复杂。不过,如果您只需要一个列表,可以在 MS 网站上找到: https://azure.microsoft.com/en-us/support/legal/offer-details/
不幸的是,我认为这是不可能的。我认为为您的问题找到解决方案是明智的。
也许您可以添加请求以在将来添加此功能: https://github.com/Azure/azure-docs-powershell/blob/master/azuresmps-4.0.0/AzureRM.Profile/Get-AzureRmSubscription.md
可以通过非官方方式获取 Azure 门户本身使用的优惠 ID。我用我的订阅测试了它并且它有效。它可能会导致特定优惠 ID 出现问题。请对此提供反馈。
这些是必需的步骤:
获取 Bearer 认证令牌
Assemble 一个 POST REST 调用
- URL: https://s2.billing.ext.azure.com/api/Billing/Subscription/Subscription
- Headers:使用您的 Bearer 令牌添加授权 header(授权:Bearer ej...)
- 请求Body类型:application/json
- 请求Body内容:
{ "subscriptionId": "########-####-####-####-############" }
结果如下所示:
{ "accountInfo": { "userRole": 6, "billingSystemType": 2, "isAccountAdmin": true, "isTokenMatch": false, "locale": "en-US", "currency": "EUR", "countryCode": "DE", "accountAdminEmail": "****@****.com", "commerceAccountId": "########-####-####-####-############", "currencyMigrationInfo": null, "displaySpecifiedRole": false }, "essentials": { "offerId": "MS-AZR-0063P", "roles": { "2": null, "4": { "isDirectCancel": true }, "5": null }, "freeMetersEndDate": null, "provisioningStatus": 1, "hasPendingTransfer": false } }
现在可以使用 Resource Graph Explorer 通过类似于以下的查询从门户网站完成此操作:
resourcecontainers
| where type == "microsoft.resources/subscriptions"
| project name, properties.subscriptionPolicies.quotaId
没有,但是已经有一个功能请求,please vote for it。
有一种官方方法可以使用 Azure REST API 获取优惠 ID。确保使用 API 版本作为 api-version=2019-10-01
您可以run\try点击下方url试试: https://docs.microsoft.com/en-us/rest/api/consumption/usagedetails/list#code-try-0
当然,您需要使用您的 Azure 用户 ID 和密码登录 try\test。
您将收到如下所示的响应,其中包含报价 ID:
更多详细信息,请参阅使用详情-列表API:https://docs.microsoft.com/en-us/rest/api/consumption/usagedetails/list。
注意:这不是 PowerShell 方式,但您可以使用 PowerShell/curl 调用 REST Api。参考https://mauridb.medium.com/calling-azure-rest-api-via-curl-eb10a06127