SSIS configuring parameter value from PowerShell

2019-09-16 16:25发布

I am trying to set parameter value using the following code in powershell

$IspacFilePath = "D:\SSIS\MyFirstSSIS.ispac"
$ProjectName = "MyFirstSSIS"
$SsisServer = "localhost"
$SsisNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
$assembly = [System.Reflection.Assembly]::LoadWithPartialName($SsisNamespace) #| Out-Null;
# Create a connection to the server
$SqlConnectionstring = "Data Source=" + $SsisServer + ";Initial Catalog=testdb;Integrated Security=SSPI;"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnectionstring
# Create the Integration Services object
$ssisServer = New-Object $SsisNamespace".IntegrationServices" $sqlConnection

$Catalog = $ssisServer.Catalogs["SSISDB"]
$Folder = $Catalog.Folders[$FolderName]

if($Folder.Projects.Contains($ProjectName)) {
    Write-Host "Deploying" $ProjectName "to" $FolderName "(REPLACE)"
}
else
{
    Write-Host "Deploying" $ProjectName "to" $FolderName "(NEW)"
}

[byte[]] $IspacFile = [System.IO.File]::ReadAllBytes($IspacFilePath)
$Folder.DeployProject($ProjectName, $IspacFile)
$Project = $Folder.Projects[$ProjectName]
foreach ($Parameter in $Project.Parameters)
{
    $Parameter.ReferencedVariableName ="$SqlConnectionstring"
}

Which is giving me the result as attached, I am not getting the required configuration so can some one tell me how can I set this

enter image description here

1条回答
虎瘦雄心在
2楼-- · 2019-09-16 17:20

Below is the code I would use to set a package level parameter, I'm assuming that it would be the same for a project level parameter:

$project.Parameters['param_name'].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal, $param_value)
$project.Alter()

Also for any connections you do not have to explicitly create parameters as these are created automatically for you. So for example if you had a connection called targetserver, SSIS will add a parameter to the Parameters collection called: CN.targetserver.ConnectionString.

查看更多
登录 后发表回答