title: PowerShell script to refresh tabular cube on Azure
body: <p>I need to setup powershell script for refreshing tabular model cube on Azure, Microsoft SQL Analysis Server (version 15.0.0.52). 
  I wrote this solution, but every time when it's executed I have same errors.</p>
  
  <pre><code>   # PowerShell code 
  # Connect to a connection to get TenantId and SubscriptionId
  $Connection = Get-AutomationConnection -Name "AzureRunAsConnection"
  $TenantId = $Connection.TenantId
  $SubscriptionId = $Connection.SubscriptionId
  
  # Get the service principal credentials connected to the automation account. 
  $null = $SPCredential = Get-AutomationPSCredential -Name "Samcred"
  
  # Login to Azure ($null is to prevent output, since Out-Null doesn't work in Azure)
  Write-Output "Login to Azure using automation account 'Samcred'."
  $null = Login-AzureRmAccount -TenantId $TenantId -SubscriptionId $SubscriptionId -Credential $SPCredential
  
  # Select the correct subscription
  Write-Output "Selecting subscription '$($SubscriptionId)'."
  $null = Select-AzureRmSubscription -SubscriptionID $SubscriptionId
  
  # Get variable values
  $DatabaseName = Get-AutomationVariable -Name 'DatabaseName'
  $AnalysisServerName = Get-AutomationVariable -Name 'AnalysisServerName'
  
  # Show info before processing (for testing/logging purpose only)
  Write-Output "Processing $($DatabaseName) on $($AnalysisServerName)"
  
  #Process database
  $null = Invoke-ProcessASDatabase -databasename $DatabaseName -server $AnalysisServerName -RefreshType "Full" -Credential $SPCredential 
  
  # Show done when finished (for testing/logging purpose only)
  Write-Output "Done"
  </code></pre>
  
  <p>Errors are:</p>
  
  <pre><code>Login to Azure using automation account 'Samcred'.
  Login-AzureRmAccount : unknown_user_type: Unknown User Type
  At line:12 char:9
  + $null = Login-AzureRmAccount -TenantId $TenantId -SubscriptionId $Sub ...
  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : CloseError: (:) [Add-AzureRmAccount], AadAuthenticationFailedException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.AddAzureRMAccountCommand
  
  Selecting subscription 'fb3456-56c2-40a2-aae6-9eeace345678'.
  Select-AzureRmSubscription : Run Login-AzureRmAccount to login.
  At line:16 char:9
  + $null = Select-AzureRmSubscription -SubscriptionID $SubscriptionId
  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [Set-AzureRmContext], PSInvalidOperationException
      + FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
  
  Processing TabCube on asazure://westus.asazure.windows.net/dex:rw
  Invoke-ProcessASDatabase : Exception has been thrown by the target of an invocation.
  At line:26 char:9
  + $null = Invoke-ProcessASDatabase -databasename $DatabaseName -server  ...
  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Invoke-ProcessASDatabase], TargetInvocationException
      + FullyQualifiedErrorId : 
  System.Reflection.TargetInvocationException,Microsoft.AnalysisServices.PowerShell.Cmdlets.ProcessASDatabase
  
  Done
  </code></pre>
  
  <p>Any advice about this ? </p>