Solved

SSIS capture PowerShell output

Posted on 2014-04-16
3
1,527 Views
Last Modified: 2016-02-10
I  am testing to see if it is possible to capture PS output in SSIS. I am an SSIS newbie. I created a script with one line of code:

test.ps1
$result = Write-Output "Exit"

I can run test.ps1 successfully from an Execute Process Task.
Here is how I set up the Execute Task:

Executable = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments = -file "C:\Scripts\testing\SSIS\SSIS_Test.ps1"
StandardOutputVariable = User::Result

User::Result Variable I created in the Execute Task:
Container = Package
Name = Result
Namespace = User
Value Type = String

I have created an Execute SQL Task to insert the results in a test database. Using:

SQLSourceType = Direct input
SQLStatement = INSERT INTO dbo.Table_1(test) VALUES (?)

and a Parameter Mapping in the Execute SQL Task
VN = User::Result
Direction = Output
Data Type = Long
Paramter Name = 0
Parameter Size = -1

The workflow runs but the output is a null value.

How can I capture the output of $Result for the PS script into a variable in SSIS and use that variable to update a DB??

Thanks
0
Comment
Question by:greetrufus
  • 2
3 Comments
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
greetings.

Please take a look at this article from databasse journal

I think it may contain the information you are looking for :)

http://www.databasejournal.com/features/mssql/ssis-2012-using-powershell-to-configure-project-environments.html
0
 

Accepted Solution

by:
greetrufus earned 0 total points
Comment Utility
I was able to accomplish this by creating a variable (User::PSOutput) in the StandardOutputVariable. of the Execute Process Task.

I created a Precedence Constraint from the EPT and used an Expression.
I was unable to query off the exact output, but was able to query using NotNull
So I created the following Expression:
@[User::PSOutput] != ""

This PC was connect to a send mail step that would send an email and capture the PSOutput variable as the subject of the email.

On a second PS, I added the opposite Expression:
@[User::PSOutput] == ""

So if the PSOutput was null, the package would continue.

This did force me to write very clean PowerShell code with no outputs except for errors.

Hope this helps someone else!!
0
 

Author Closing Comment

by:greetrufus
Comment Utility
No one else gave a more suitable answer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now