获取表格数据库的连接数据源

Get Connection dataSource of Tabular database

使用 SQL2017 版本 14.0.1.439。我需要使用 Powershell 更改表格数据库中连接的数据源路径。

这是我的代码:

$ServerName="localhost\tabular"
$loadInfo = 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
 Write-Output ("Server '{0}' not found" -f $ServerName)
 break
}
foreach ($d in $server.Databases )
{
Write-Output ( "Database: {0}; Status: {1}; Size: {2}MB; Data Sources: {3} " -f $d.Name, $d.State, ($d.EstimatedSize/1024/1024).ToString("#,##0"), $d.DataSources.Count )
}

我的问题是,$d.DataSources.Count 始终为 0。

我正在寻找使用 PS 编辑它的方法。

您应该通过 Model.Datasources 访问数据源 我可以确认以下代码 returns 我的表格模型的数据源数量。

$ServerName="localhost\tabular"
$loadInfo = 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")

$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)

if ($server.name -eq $null) {
 Write-Output ("Server '{0}' not found" -f $ServerName)
 break
}
foreach ($d in $server.Databases )
{
     Write-output ( "Database: {0}; Status: {1}; Size: {2}MB; Data Sources: {3} " -f $d.Name, $d.State, ($d.EstimatedSize/1024/1024).ToString("#,##0"), $d.Model.DataSources.Count )
}