CURRENT STATUS: The forums you are now looking at are CLOSED. Visit the new forums.


Passing SSIS variable to Powershell

Creating PowerShell extensions in Visual Studio? Post here! Monitored by MVP Doug Finke.
Forum rules
1. Use the CODE or POWERSHELL buttons to format code and commands.
2. Avoid the use of obscure and punctuation aliases (like ? and %).
3. Don't apologize for being a "noob." We don't mind.
4. If we help you solve your question, please click the green SOLVED checkmark.

More forums tips & etiquette

Passing SSIS variable to Powershell

Postby Mike777 » Tue Oct 02, 2012 11:21 pm

Hi All,

Please be kind. This is my first post and I am new to Powershell.
I am executing a Powershell script from my SSIS package by using the Process Task transformation.
I am trying to Pass a SSIS variable to Process Task so it will use the variable to download the correct file.
The download from a static or hardcoded file name works fine if it is already in the PS script. It fails when I try to pass the
variable to the script. Can anyone explain or show me how to pass a variable to a PS script using SSIS?
I commented out several attempts with the ## sign.

Thank you in advance very much.

Here is my code:
##ananytics_ndw_DownloadSelectedHistoricWeather.ps1
##
## File being downloaded is the Historic Weather text file - file format (DS3505)
## This will down load a file that was created by the NCDC (National Climate Data Center) because it was
## manaully requested for a specifc STATE, YEAR on the weather website.
##
CLEAR
param(
[string]SelectedFileName
)

$shell_app=new-object -com shell.application
if(!$?){
echo "Error Creating Shell Application"
exit 99
}
$clnt = new-object System.Net.WebClient
if(!$?){
echo "Error Creating WebClient"
exit 99
}

## inside varible works fine
##set-variable -name newfilename -value "3816995904168dat.txt"
##$file = get-variable -value newfilename

## trying to get it to pass from the ssis task Execute proccess task to powershell is the problem


$file = $ssis.variables["User::SelectedFileName"];

##$file = Get-Variable -value $SelectedFileName
###$file = $ssis Variables SelectedFileName

$url = "http://www1.ncdc.noaa.gov/pub/orders/" + "$file"

$file_mypath = "x:\SQL\DATA\NDW\Weather\Historical\SelectedHistoricWeather" + "\$file"

if(!$?){
echo "Error Obtaining File Location"
exit 99
}
$clnt.DownloadFile($url, $file_mypath)


## END OF CODE
Mike777
 
Posts: 1
Joined: Mon Oct 01, 2012 10:48 pm

Re: Passing SSIS variable to Powershell

Postby coderaven » Wed Oct 03, 2012 12:42 pm

It seem to me that you are not passing the parameter correctly. I would start looking here. I have no experience with SSIS jobs.
Allan Miller
Just someone excited about PowerShell.
User avatar
coderaven
 
Posts: 129
Joined: Mon Aug 13, 2012 9:07 pm
Location: lubbock texas


Return to PowerShell for Developers

Who is online

Users browsing this forum: No registered users and 1 guest