azure - 使用 powershell 在 Azure 自动化帐户中设置 API 版本
问题描述
我在 powershell azure 自动化运行手册中使用了以下消耗使用详细信息。
Get-AzureRmConsumptionUsageDetail -StartDate $startDate -EndDate $endDate -ResourceGroup
相同的命令和运行手册在另一个订阅中运行良好。但是在其中一个订阅中,它给出了以下错误
当前 api 版本不支持订阅范围使用。请使用 2019-10-01 之后的 api 版本
如何在 Azure Powershell 中设置 apiversion?
解决方案
Get-AzConsumptionUsageDetail
没有ApiVersion
参数。
我的解决方法是使用下面的命令。首先,使用您的登录帐户获取令牌,然后请求API以获取使用详细信息。错误提到的api-version
是2019-10-01。
# login
Connect-AzAccount
# get accessToken
$resource = "https://management.azure.com"
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$accessToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $resource).AccessToken
#request REST API
$uri = "https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?api-version=2019-10-01"
Invoke-RestMethod -Method 'Get' -Uri $uri -Headers @{ Authorization = "Bearer " + $accessToken }
{scope}
应该代替与使用细节操作相关的范围。您可以参考文档以获取更多详细信息。
推荐阅读
- android - Android ExampleInstrumentedTest 运行失败并显示“测试框架意外退出”
- arrays - 要映射的对象数组
- php - 如何在laravel的mysql中插入摊销时间表
- python - 在 Python3 中将整数数组转换为二进制:“TypeError:只能转换整数标量数组?”
- c++ - 如何将 .dat 中的值分配给 C++ 中的矩阵?
- python - 我想将两个文本变量和文本添加到 tkinter 中的标签小部件
- javascript - 带有下拉问题的 mCustomScrollBar
- python - 如何在树视图中的选定项目内向上或向下移动焦点
- python - 将来自 google collab 的训练结果保存为 CSV
- smooth-scrolling - locomotive.js 加载时平滑滚动更新()