【问题标题】:I need reource code of main.iam.ad.ext.azure.us我需要 main.iam.ad.ext.azure.us 的资源代码
【发布时间】: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


【解决方案1】:

我找到了解决方案。在我上面的脚本中^^,我替换了

$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")

$apiToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id, $null, "Never", $null, "ee62de39-b9b0-4886-aa58-08b89c4e3db3")

现在它可以工作了。这是响应的示例:

name            : Office 365 E3 - GCCHIGH
accountId       : XXXXXX-XXXX-4427-8719-XXXXXXXXXXXX
accountSkuId    : TEST:ENTERPRISEPACK_USGOV_GCCHIGH
availableUnits  : 0
totalUnits      : 1
consumedUnits   : 1
skuId           : aea38a85-XXXX-XXXX-aa00-XXXXXXXXXXXX
isDepartment    : False
warningUnits    : 0
serviceStatuses : {@{provisioningStatus=Success; servicePlan=}, @{provisioningStatus=Success; servicePlan=}, @{provisioningStatus=Success; servicePlan=}, @{provisioningStatus=Success; servicePlan=}...}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-08
    • 2010-09-08
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多