我正在尝试使用 Powershell 获取订阅数据的 Azure 计费数据。
主要从 MSDN https://docs.microsoft.com/ja-jp/rest/api/consumption/usagedetails/list检查文档
$loginUri = "https://login.microsoft.com"
$body =@{
client_id = XXXX
client_secrect = XXXXXXXX
resource = "https://management.core.windows.net"
grant_type = "client_credentials"
}
$oauth = Invoke-RestMethod -Method Post -Uri $loginUrl/$TenantID/oauth2/token?api-version=1.0 -Body $body
# SubscriptionID and Billing Period
$SubscriptionId = '<Your subscription GUID here>'
$billingperiod = '202006-1'
#Create the REST-URL
$usageURL = "https://management.azure.com/subscriptions/$subscriptionid/providers/Microsoft.Billing/billingPeriods/$billingperiod/providers/Microsoft.Consumption/usageDetails?api-version=2017-11-30"
成功获得身份验证令牌后,运行请求 uri 时出错
“AuthenticationFailed”,对象 ID 为“XXXX”的客户端“XXXXXX”无权在范围“/subscriptions/XXXX”上执行操作“Microsoft.Consumption/usageDetial/read”或范围无效。如果最近授予访问权限,请刷新您的凭据。
可能是因为我没有使用 APPID 并生成 APPkey 来获取凭据,而是在 Graph API 中获取令牌时使用应用程序的 client_secret ?