问题
I'm currently trying to create an automation runbook to process a cube in Azure. I've tried multiple PowerShell scripts like this one :
$AzureCred = Get-AutomationPSCredential -Name "RefreshTest"
Add-AzureRmAccount -Credential $AzureCred | Out-Null
Invoke-ProcessASDatabase -databasename "MKTGCube" -server "AzureServerName" -RefreshType "Full" -Credential $AzureCred
With that kind of error (despite the fact that I installed the SQLServer module).
Invoke-ProcessASDatabase : The term 'Invoke-ProcessASDatabase' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
Or this script :
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
##Getting the credential which we stored earlier.
$cred = Get-AutomationPSCredential -Name 'CredMat'
## Providing the Server Details
$ServerName = "AzureServerName"
Invoke-ProcessASDatabase -databasename "MKTGCube" -server $ServerName –ProcessType "ProcessFull"
$error[0].Exception.Message
$error[0].Exception.StackTrace
With that error message.
Invoke-ProcessASDatabase : Authentication failed: User ID and Password are required when user interface is not
available.
At line:32 char:1
Invoke-ProcessASDatabase -databasename "MKTGCube" -server $ServerName ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [Invoke-ProcessASDatabase], ArgumentException
FullyQualifiedErrorId : System.ArgumentException,Microsoft.AnalysisServices.PowerShell.Cmdlets.ProcessASDatabase
I think the problem is linked to the credentials because we need to provide ones to access the source database but I have no ideas on how to do it through a PowerShell script. Any idea ?
Thanks a lot.
回答1:
You need import module Azure.AnalysisServices
and SqlServer
to your automation account.
You could import these two module from this link and this link.
Note: There is a mistake in your script. You should use Login-AzureASAccount
not Add-AzureRmAccount
to login, you could use the following example:
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureAnalysisServicesAccount -RolloutEnvironment "southcentralus.asazure.windows.net" -ServicePrincipal -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint -TenantId $Conn.TenantID
Invoke-ProcessTable -Server "asazure://southcentralus.asazure.windows.net/myserver" -TableName "MyTable" -Database "MyDb" -RefreshType "Full"
More information about this please check this blog.
来源:https://stackoverflow.com/questions/49507272/cube-refresh-with-automation-account-in-azure-ssas