Restart-AzAnalysisServicesInstance:响应状态代码不表示成功:401(未经授权)

Restart-AzAnalysisServicesInstance : Response status code does not indicate success: 401 (Unauthorized)

我有一个带有 S1 SKU 的 Azure Analysis Services。有一个 SPN 在 AAS 上拥有 OWNER RBAC。我正在尝试通过 Automation Account 到 运行 Restart-AzAnalysisServicesInstance cmdlet 使用 PowerShell 5.1 Runbook

当我 运行 运行手册时,我看到错误:

Restart-AzAnalysisServicesInstance : Response status code does not indicate success: 401 (Unauthorized).

但是,当我在本地 运行 cmdlet 时,使用我在 Windows Powershell ISE 中 Connect-AzAccount 的凭据,它起作用了。我也是 AAS 的所有者。

这是操作手册:

    # Init
    $ErrorActionPreference = 'Stop'
    $AutomationAccountConnectionName = "Name of my Connection that uses the Owner SPN" 

    # Get Automation connection (SPN connection details)
    $servicePrincipalConnection = Get-AutomationConnection -Name $AutomationAccountConnectionName 
    Write-Output "Connected using SPN:"
    $servicePrincipalConnection

    # Connect using SPN
    Write-Output "Connecting to AZ using the SPN connection:"
    $Connection | ConvertTo-Json
    $azContext = Connect-AzAccount -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -Tenant $servicePrincipalConnection.TenantId -ServicePrincipal
    Write-Output ("Connected to azure using certificate with app id : " + $Connection.AppId)
    
   # Get AAS
    $aasServer = "test113aas"
    $subscriptionId = "GUID of my azure subscrition"
    Select-AzSubscription -Subscription $subscriptionId
    $resourceObj = Get-AzAnalysisServicesServer -Name $aasServer 
    $ResourceObj
    $AnalysisServer = $resourceObj.Name
    $AnalysisServerLocation = 'northeurope'
    $ModelName = 'adventureworks'

    # # Connect AAS Account => This did not help as well
    # Write-Host "Adding AAS Account"
    # Add-AzAnalysisServicesAccount -RolloutEnvironment "$AnalysisServerLocation.asazure.windows.net" `
    #     -ServicePrincipal -ApplicationId $servicePrincipalConnection.ApplicationId `
    #   -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint -TenantId $servicePrincipalConnection.TenantId
    
    # Restart AAS server
    Write-Host "Server's full name is $($resourceObj.ServerFullName)"
    Write-Host "$AnalysisServer : Preparing to Restart the Analysis Server"
    $result = Restart-AzAnalysisServicesInstance –Instance $resourceObj.ServerFullName -PassThru # returns true if successful
    $result

知道我在这里遗漏了什么吗?文档:https://docs.microsoft.com/en-us/powershell/module/az.analysisservices/restart-azanalysisservicesinstance?view=azps-7.2.0

我什至尝试 运行在 Azure PowerShell 核心函数中使用相同的方法,因为该文档适用于 PowerShell 7+,但无济于事。

原来我们需要在调用 cmdlet 之前将客户端的 IP 列入白名单。

错误信息本来可以更准确。