【发布时间】:2021-06-06 14:49:45
【问题描述】:
我需要以编程方式收集有关总许可和已分配许可的信息。 此处描述的方式:https://tech.nicolonsky.ch/manage-azure-ad-group-based-licensing-with-powershell/ - 不适用于 AzureUSGovernment 环境。出现以下错误:“”Get-AADLicenseSku : AADSTS900382:Cross Cloud 请求中不支持机密客户端。”
所以,我正在寻找一种方法来调整它并在 AzureUSGovernment 上使用它。但我找不到 main.iam.ad.ext.azure.us 的资源 ID 据我了解,main.iam.ad.ext.azure.com 的 ID 是 74658136-14ec-4630-ad9b-26e160ff0f。但我不明白它来自哪里。 预先感谢您的帮助。 我根据原始脚本创建了一个脚本:
$context = Get-AzContext
if ($null -eq $context) {
$null = Connect-AZAccount -EA stop
$context = Get-AzContext
}
$apiToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id, $null, "Never", $null, "https://main.iam.ad.ext.azure.us")
$header = @{
'Authorization' = 'Bearer ' + $apiToken.AccessToken.ToString()
'Content-Type' = 'application/json'
'X-Requested-With' = 'XMLHttpRequest'
'x-ms-client-request-id' = [guid]::NewGuid()
'x-ms-correlation-id' = [guid]::NewGuid()
}
Write-Verbose "Connected to tenant: '$($context.Tenant.Id)' as: '$($context.Account)'"
$baseUrl = "https://main.iam.ad.ext.azure.us/api/"
try {
$request = Invoke-WebRequest -Method Get -Uri $($baseUrl + "AccountSkus") -Headers $header
$requestContent = $request | ConvertFrom-Json
return $requestContent
}
catch {
# convert the error message if it appears to be JSON
if ($_.ErrorDetails.Message -like "{`"Classname*") {
$local:errmsg = $_.ErrorDetails.Message | ConvertFrom-Json
if ($local:errmsg.Clientdata.operationresults.details) {
Write-Error $local:errmsg.Clientdata.operationresults.details
}
else {
Write-Error $local:errmsg
}
}
else {
Write-Error $_
}
}
但它失败并出现以下错误: “调用-RestMethod : 401 - 未经授权:由于凭据无效,访问被拒绝。 服务器错误
401 - 未经授权:由于凭据无效,访问被拒绝。 您无权使用您提供的凭据查看此目录或页面。"
我尝试使用用户帐户和服务主体。全局管理员角色分配给两者。
【问题讨论】:
-
当您说它“在 AzureUSGovernment 环境中不起作用”时,您能否详细说明您正在运行的具体内容以及您看到的错误/行为?
-
我在 AureUSGovernment 上运行 Get-AADLicenseSku 时遇到的错误是“Get-AADLicenseSku:AADSTS900382:跨云请求中不支持机密客户端。”我更新了使用 az-government env 的脚本,但现在我不断收到 401 - 未经授权:由于凭据无效,访问被拒绝”。我将全局角色分配给了我自己的用户帐户,但它没有帮助。
标签: azure-gov