使用Powershell在连接管理器选项卡中部署并设置Ispac connectionstring属性

时间:2018-11-23 09:48:33

标签: powershell

我可以使用下面的代码成功地使用powershell部署ssis项目,但是,我还想在“连接管理器”选项卡中设置connectionstring属性(在项目级别)。我试图搜索,但找不到任何来源。有人可以帮忙吗?enter image description here

# Variables
$SSISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"

$TargetServerName = "localhost"
$TargetFolderName = "Project1Folder"
$ProjectFilePath = "C:\Projects\Integration Services Project1\Integration Services Project1\bin\Development\Integration Services Project1.ispac"
$ProjectName = "Integration Services Project1"

# Load the IntegrationServices assembly
$loadStatus = [System.Reflection.Assembly]::Load("Microsoft.SQLServer.Management.IntegrationServices, "+
    "Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL")

# Create a connection to the server
$sqlConnectionString = `
    "Data Source=" + $TargetServerName + ";Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

# Create the Integration Services object
$integrationServices = New-Object $SSISNamespace".IntegrationServices" $sqlConnection

# Get the Integration Services catalog
$catalog = $integrationServices.Catalogs["SSISDB"]

# Create the target folder
$folder = New-Object $SSISNamespace".CatalogFolder" ($catalog, $TargetFolderName,
    "Folder description")
$folder.Create()

Write-Host "Deploying " $ProjectName " project ..."

# Read the project file and deploy it
[byte[]] $projectFile = [System.IO.File]::ReadAllBytes($ProjectFilePath)
$folder.DeployProject($ProjectName, $projectFile)

Write-Host "Done."

1 个答案:

答案 0 :(得分:0)

完成这项工作。只需设置CM.ConfigurationDatabase.ConnectionString参数的值即可。

$Project = $folder.Projects[$ProjectName]

$cm_value = "test"

$Project.Parameters["CM.ConfigurationDatabase.ConnectionString"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal, $cm_value)