3

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""
      }
    }
  }
}" 
Joseph
  • 530
  • 3
  • 15
  • 37

2 Answers2

2

You can try using Add-AzureAnalysisServicesAccount to login to an instance of Azure Analysis Services server. See below:

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

Invoke-ASCmd ...

Check document Add-AzureAnalysisServicesAccount for more information. See this similar thread.

You can also try providing the credentials for Invoke-ASCmd command:

Invoke-ASCmd -Server "" -Database "" -Credential $psCred -TenantId $azureTenantId -ServicePrincipal -Query ""
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Thanks, that works. Added some extra code at the beginning to get rid of the argument issue. – Joseph Sep 23 '20 at 05:26
  • Levi Lu-MSFT - AzureDevOps uses a different IP address every time I run the script, If I whitelist one, the next time it tries to deploy with different IP address. Do you have a work around for this? – Joseph Sep 23 '20 at 08:55
1
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 ....
Joseph
  • 530
  • 3
  • 15
  • 37
  • Hi Joseph, I am getting AADSTS7000011 when I am using service principal, do we need any special configuration for the service principal? Later, I tried with my credentials, I am getting error AADSTS7000016. Do I need any specific permission for my credentials? Please reply, and please complete Invoke-Ascmd in your accepted answer. – Ashish-BeJovial Sep 17 '21 at 09:59