ConnectionString property not printing connection string

前端 未结 3 1817
独厮守ぢ
独厮守ぢ 2021-01-23 07:19

I am trying to get the connection string of a database datasource with the following script:

   $Analysis_Server = New-Object Microsoft.AnalysisServices.Server           


        
3条回答
  •  忘了有多久
    2021-01-23 07:55

    found this in a post here: http://www.mrtsql.com/2011/03/powershell-updating-analysis-services.html

    See if this function in that post helps you out.

    function UpdateDataSources()
    {
       # Lets get our server name
       $SSASServerName="$env:ComputerName\" + $SSASInstanceName
       $MyConnection = New-Object("Microsoft.AnalysisServices.Server")
       $MyConnection.Connect($SSASServerName)
       # lets return the number of data sources
       [int]$DataSourcecount=$MyConnection.Databases[$DatabaseName].DataSources.count
       for ($count=0; $count -ne $DataSourcecount;++$count)
       {
         $MyCS=$MyConnection.Databases[$DatabaseName].DataSources[$count].ConnectionString
        $NewCS=setNewValue -MyCS $MyCS -Pattern "Data Source=" -ReplaceWith $DataSourceServer
    
         if ($PW.Length -ne 0)
         {
            $NewCS=setNewValue -MyCS $NewCS -Pattern "Password=" -ReplaceWith $PW
         }
         if ($UserName.length -ne 0)
         {
            $NewCS=setNewValue -MyCS $NewCS -Pattern "User ID=" -ReplaceWith $UserName
         }
         $MyConnection.Databases[$DatabaseName].DataSources[$count].ConnectionString=$NewCS
         # write the change back to SSAS
         $MyConnection.Databases[$DatabaseName].DataSources[$count].update()
    
         write-output $NewCS
         }
    }
    

提交回复
热议问题