I am using PowerShell to deploy a project to SSISDB and to set a project parameter. (This is loosely based on this article : http://blogs.msdn.com/b/mattm/archive/2011/11/17/ssis-and-powershell-in-sql-server-2012.aspx )
The script creates a folder, and successfully deploys the project from the isPac file. The package in the project runs successfully from SSMS Integration Services Catalog node.
I am attempting to change the value of a project parameter. It appears that the parameter gets changed, but that the change is not persisted to SSISDB.
The following script illustrates the problem I am having.
Run the script: .\TestPPrm (within PowerShell) - this displays the before/after parameter values
Run the script again as: .TestPPrm 1 - this only displays the parameter value, which show the original value.
The project itself contains a package with a script task that simply displays a variable using FireInformation(). The project has a project parameter named PParm2, defined as a string with arbitrary content.
Script:
param ([boolean] $show = 0)
"-- show $show"
$global:cat = 0
#-------------------------------------------
function AccessCtlg {
# Load the IntegrationServices Assembly
$loadStatus = [Reflection.Assembly]::Load("Microsoft"+
".SqlServer.Management.IntegrationServices" +
", Version=11.0.0.0, Culture=neutral" +
", PublicKeyToken=89845dcd8080cc91")
# Store the IntegrationServices Assembly namespace to avoid typing it every time
$global:ISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
Write-Host "Connecting to server ..." -f cyan
# Create a connection to the server
$global:constr = "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;"
$global:con = New-Object System.Data.SqlClient.SqlConnection $constr
# Create the Integration Services object
$global:ssis = New-Object $ISNamespace".IntegrationServices" $con
# Get the catalog reference
if ($global:ssis.Catalogs.Count -gt 0)
{
Write-Host "Opening SSISDB Catalog ..." -f cyan
$global:cat = $global:ssis.Catalogs["SSISDB"]
}
else
{
Write-Host "SSISDB Catalog does not exist ..." -f red
}
}
#------------------------------------------------------
function ShowPPrm ($p, $when) {
$n = $p.Name
Write-Host "Parameter: $n ($when)" -f green
if($p.DefaultValue.length) {
$v = $p.DefaultValue
} else {
$v = $p.DesignDefaultValue
}
$t = $p.DataType
Write-Host @"
Value : $v
DataType: $t
"@ -f darkgreen
}
#-------------------------------------------------------
# Set project parameters
function SetPrjPrms($project, $parm, $value) {
Write-Host "Setting project parameters ..." -f cyan
$lit = [Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal
$xp = $project.Parameters[$parm]
ShowPPrm $xp "Before"
$xp.Set($lit, $value)
ShowPPrm $xp "After"
}
#------------- Main ------------
AccessCtlg # Open SSISDB
$project = $cat.Folders['Example'].Projects['DeployTest'] # Get the project reference
if($show) {
$xp = $project.Parameters["PParm2"]
ShowPPrm $xp "*"
} else {
SetPrjPrms $project "PParm2" "The quick brown fox." # Set the project parameters
}