使用AMO PowerShell执行XMLA不会创建度量

时间:2017-06-09 16:41:53

标签: powershell deployment ssas-tabular amo

我编写了一个PowerShell脚本来自动部署SSAS多维数据集。我使用部署向导生成XMLA文件,然后使用PowerShell AMO命令来部署它。但是,当我运行它时,会创建表格数据库,但缺少所有度量。从SQL Management Studio运行相同的XMLA或使用Invoke-ASCmd生成包含其中所有度量的正确数据库。我在“调用”命令中缺少选项或其他内容吗?

[CmdletBinding()]
Param(
# InputDir is required
[Parameter(Mandatory=$True,Position=1)]
[string]$InputDir,

# Server is optional 
[Parameter(Mandatory=$False,Position=2)]
[string]$Server=$env:computername

)

# Output execution parameters.
"Executing with the following parameters:"
"  InputDir: $InputDir"
"  AS Database Server: $Server`n"

$XmlaDir = Resolve-Path($InputDir)
$Xmla = Join-Path -Path $XmlaDir -ChildPath  '\Model.xmla'
$ASFiles = Get-ChildItem -Recurse -Path $InputDir -Filter *.asdatabase
$Count = $ASFiles.Count

If($Count -ne 1)
{
   Write-Host("`ERROR: Count asdatabase file(s) found at $inputdir")
   Exit 1
}

$ASDatabase = $ASFiles[0].FullName
Write-Host("`nUsing $ASDatabase for deployment.")
Write-Host("`nAttempting to create $Xmla ...`n")

# Use Analysis Services Deployment Utility to generate XMLA file from 
.asdatabase file
$Script:ASDeployWizard = "E:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment.exe
"
$Arguments = @("`"$ASDatabase`"", "/s", "/o:`"$Xmla`"")
Start-Process -FilePath $Script:ASDeployWizard -ArgumentList $Arguments -Wait

If ((-Not $?) -Or -Not (Test-Path $Xmla))
{
   "Cannot generate deployment descriptor. Deployment aborted."
   Exit 1
}

Write-Host("XMLA deployment descriptor generated.`n")

Try { 
Import-Module SQLPS -DisableNameChecking 

# Deploy Cube
"Invoking deployment script. This may take several minutes...`n"

$AS = New-Object Microsoft.AnalysisServices.Server 
$AS.connect($Server)
$CubeDescriptor = [string](Get-Content $Xmla)

$Results = $AS.Execute($CubeDescriptor)

Foreach ($r in $Results) {
  $r.Messages.Description
}

"Done.`n"
} Catch {   
  Write-Host($_.Exception.GetType().FullName + "`n" + $_.Exception.Message + "`n")
  Write-Host("Deployment FAILED.`n")
}
Exit 0 

0 个答案:

没有答案