Sql-Server-2016

使用 Powershell 查詢 SSAS 連接字元串

  • July 8, 2019

我想從 SSAS 中檢索每個 OLAP 多維數據集或數據庫的現有連接字元串。數據將用於控制/審計報告。

我發現 Powershell 允許我像目錄一樣鑽入 SSAS,我可以看到我在追求什麼,但不知道如何查詢它。

在 Powershell 中,我可以深入到這裡:

PS SQLSERVER:\SQLAS\LAP123\Default\databases\EnvironmentalAnalysisService\Datasources> 

我可以看到我想要的細節:

Name                      Isolation     Max Connections Connection String                       
----                      ---------     --------------- -----------------                       
Environmental Data Mart   ReadCommitted              10 Provider=SQLNCLI11.1;Data               
                                                       Source=LAP123;Integrated                
                                                       Security=SSPI;Initial                   
                                                       Catalog=EnvironmentalDataMart

在這種情況下伺服器;LAP123 和數據庫:EnvironmentalDataMart

如何從 Powershell 中獲取我想要的項目,例如查詢?

嗚呼!!!

# Add the AMO namespace
$loadInfo = [Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices”)

## Connect and get the edition of the local server
$connection = “localhost”
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($connection)

foreach ($d in $server.Databases )
{   

   Write-Output ( “Database: {0}, String {1}:” -f $d.Name, $d.DataSources.ConnectionString)        

} # Databases

返回:

Database: EnvironmentalAnalysisService, String Provider=SQLNCLI11.1;Data Source=LAP123;Integrated Security=SSPI;Initial Catalog=EnvironmentalDataMart:
Database: PerformanceAnalysisService, String Provider=SQLNCLI11.1;Data Source=DEV-EDW;Integrated Security=SSPI;Initial Catalog=PerformanceDataMart:

PS SQLSERVER:\SQLAS> 

引用自:https://dba.stackexchange.com/questions/242302