0

我编写了一个 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 
4

0 回答 0