Solved

SSIS capture PowerShell output

Posted on 2014-04-16
3
1,633 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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
Viewers will learn how the fundamental information of how to create a table.

829 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