# Passing parameters to an ssis package

**URL:** https://forums.powershell.org/t/passing-parameters-to-an-ssis-package/14296
**Category:** PowerShell Help
**Created:** [April 30, 2020, 10:36am UTC](https://forums.powershell.org/t/passing-parameters-to-an-ssis-package/14296 "2020-04-30T10:36:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)
#### Post date: [April 30, 2020, 10:36am UTC](https://forums.powershell.org/t/passing-parameters-to-an-ssis-package/14296/1 "2020-04-30T10:36:00Z")

</div>

I want to pass a parameter to an ssis package and execute it. When I run the script below, I get ‘You cannot call a method on a null-valued expression’. What am I doing wrong?

\*The process runs ok, executing the package, if I skip adding the parameter.

```
[System.Reflection.Assembly]::Load("Microsoft.SQLServer.Management.IntegrationServices, "+
"Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL") | Out-Null
$sqlConnectionString = `
"Data Source=" + $SSISServer + ";Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$SSISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
$SSIS = New-Object $SSISNamespace".IntegrationServices" $sqlConnection
$catalog = $SSIS.Catalogs["SSISDB"]
$ssisPackage = $catalog.Folders[$FolderName].Projects[$ProjectName].Packages[$PackageName]
$ssisParameter = "NetworkInternalCode"
$ssisParameterValue = "alpa"
$ssisPackage.Parameters[$ssisParameter].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal,$ssisParameterValue);
$ssisPackage.Alter()
$ssisPackage.Execute("false", $null)
```

&nbsp;

---

<div class="post-metadata">

### Author: ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)
#### Post date: [April 30, 2020, 10:38am UTC](https://forums.powershell.org/t/passing-parameters-to-an-ssis-package/14296/2 "2020-04-30T10:38:05Z")

</div>

Full exception message is:

```
Exception : System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
at CallSite.Target(Closure , CallSite , Object , ParameterValueType , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
```

---

<div class="post-metadata">

### Author: ![firmbyte](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@firmbyte](https://forums.powershell.org/u/firmbyte)
#### Post date: [April 30, 2020, 12:36pm UTC](https://forums.powershell.org/t/passing-parameters-to-an-ssis-package/14296/3 "2020-04-30T12:36:34Z")

</div>

The problem I was having was due to the parameters being at Project and not Package level.

This works;

&nbsp;

```
$sqlConnectionString = `
"Data Source=" + $SSISServer + ";Initial Catalog=master;Integrated Security=SSPI;"
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$SSISNamespace = "Microsoft.SqlServer.Management.IntegrationServices"
$SSIS = New-Object $SSISNamespace".IntegrationServices" $sqlConnection
$catalog = $SSIS.Catalogs["SSISDB"]
$ssisProject = $catalog.Folders[$FolderName].Projects[$ProjectName]
$ssisProject.Parameters["NetworkInternalCode"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal, "alpa")
$ssisProject.Parameters["ControlId"].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal, "alpa")
$ssisPackage = $ssisProject.Packages[$PackageName]
$ssisPackage.Alter()
$ssisPackage.Execute("false", $null)
```

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/passing-parameters-to-an-ssis-package/14296/4 "2024-05-16T20:29:44Z")

</div>


