Search code examples
powershellazure-devopsazure-automationazure-analysis-services

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


I am trying to refresh credentials of an (already)deployed Tabular Model via CICD using Azure DevOps. Making use of Invoke-ASCmd in PowerShell to refresh the credentials. The script works fine from local when I provide the Tenant ID, App ID and the Key. However it fails when I run it from Azure Devops with error - User ID and Password are required when user interface is not available. Here is the script:

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

Solution

  • 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 ....