Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SSIS capture PowerShell output

Posted on 2014-04-16
3
Medium Priority
?
2,011 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

604 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