?
Solved

SSIS capture PowerShell output

Posted on 2014-04-16
3
Medium Priority
?
1,882 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 40003934
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
ID: 40034482
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
ID: 40043928
No one else gave a more suitable answer
0

Featured Post

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

770 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