Invoke-ASCmd:身份验证失败:用户界面不可用时需要用户 ID 和密码

Invoke-ASCmd : Authentication failed: User ID and Password are required when user interface is not available

我正在尝试使用 Azure DevOps 通过 CICD 刷新(已经)部署的表格模型的凭据。 在 PowerShell 中使用 Invoke-ASCmd 来刷新凭据。当我提供租户 ID、应用程序 ID 和密钥时,脚本在本地运行良好。但是,当我从 Azure Devops 中 运行 它并出现错误时它失败了 - 当用户界面不可用时需要用户 ID 和密码。 这是脚本:

$azureTenantId= "TenantId"
$azurePassword = ConvertTo-SecureString "Key" -AsPlainText -Force
$azureAplicationId ="AppID"

$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 

Invoke-ASCmd `
    -Server "AnalysisServerName" `
    -Database "AdventureWorks" `
    -Query "{
  ""createOrReplace"": {
    ""object"": {
      ""database"": ""AdventureWorks"",
      ""dataSource"": ""AzureBlobs/https://abc blob core windows net/""
    },
    ""dataSource"": {
      ""type"": ""structured"",
      ""name"": ""AzureBlobs/https://abc blob core windows net/"",
      ""connectionDetails"": {
        ""protocol"": ""azure-blobs"",
        ""address"": {
          ""account"": ""abc"",
          ""domain"": ""blob.core.windows.net""
        },
        ""authentication"": null,
        ""query"": null
      },
      ""credential"": {
        ""AuthenticationKind"": ""Key"",
        ""kind"": ""AzureBlobs"",
        ""path"": ""https://abc.blob.core.windows.net/"",
        ""PrivacySetting"": ""Organizational"",
        ""Key"": ""Key""
      }
    }
  }
}" 

您可以尝试使用 Add-AzureAnalysisServicesAccount 登录到 Azure Analysis Services 服务器实例。见下文:

$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
    
Add-AzureAnalysisServicesAccount -RolloutEnvironment 'eastus.asazure.windows.net' -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal 

Invoke-ASCmd ...

检查文件Add-AzureAnalysisServicesAccount for more information. See this similar .

您也可以尝试为 Invoke-ASCmd 命令提供凭据:

Invoke-ASCmd -Server "" -Database "" -Credential $psCred -TenantId $azureTenantId -ServicePrincipal -Query ""
Import-Module Azure.AnalysisServices
$azureappid ="tesappid"
$azureTenantId= "testid"

[ValidateNotNullOrEmpty()] $userPassword = "testpwd"

$userPassword = ConvertTo-SecureString -String $userPassword -AsPlainText -Force
$userCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $azureappid, $userPassword
    
Add-AzureAnalysisServicesAccount -RolloutEnvironment 'eastus.asazure.windows.net' -Credential $userCredential -TenantId $azureTenantId  -ServicePrincipal 

Invoke-Ascmd ....