I am trying to pass a SSIS variable into a PowerShell script that is running via a Process Task within SSIS, im using SSIS 2008 if that makes any difference
Here is a copy of the powershell script im using that runs fine when executed with hardcoded values
param ([string]$SourceServer, [string]$DestinationServer, [string]$Filename )
$SourceServer = "SERVERA"
$DestinationServer = "SERVERB"
$Filename = "DbNAME.mdf"
$SourcePath = "\D$\Data\"
$DestinationPath = "\D$\Data\Backups\"
$Source = '\\' + $SourceServer + $SourcePath + $Filename
$Destination = '\\' + $DestinationServer + $DestinationPath + $Filename
copy-item -path $Source -destination $Destination -verbose
I can get the PowerShell script to run fine if I hardcode the param's , however as soon as I change it to a variable the variable value isn't being passed through
Within the process task this is the executable
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
The arguments string is being built correctly so I know the variable value is being passed in
-ExecutionPolicy Unrestricted -File "C:\Qarefresh.ps1" "DbaseA.mdf"
And here is the code for the expression
"-ExecutionPolicy Unrestricted -File \"" + "C:\\Qarefresh.ps1\" \"" + @[User::QA_FileName] + "\""
I'm relatively new to PowerShell so apologise if I have missed something basic , but i'm close to pulling out my hair with this one
Thanks in advance for any help given
You need to specify the parameter names when you invoke PowerShell.
This is the PowerShell script.
Then you can test the script from a command prompt like this, passing parameters.
And the file gets copied to the output folder.
To invoke the PowerShell script from an SSIS package, first set the necessary variables.
Then add an Execute Process Task. On the Process tab, set the Executable field.
Set the Arguments field with the following expression:
Make sure the output folder is empty before running the package. (No cheating here!)
Execute the SSIS package.
And the file is copied to the output folder.
Incidentally, you need to be careful when putting $ within double quotes, because variable names get substituted, like this: