Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help: Execute Process Task --> Powershell Command Expand / Collapse
Author
Message
Posted Wednesday, March 9, 2011 10:21 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 9:33 AM
Points: 178, Visits: 626
I occasionally run a Powershell command that add characters at the end of each line in a text file.

From a Powershell prompt I run the following command:
(get-content "C:\Some Folder\someFile.txt")| foreach-object{$_+"xxxxx"}|set-content "C:\Some Folder\someFile.txt"

I tried to set that up to run from an Execute Process Task, but I'm not doing something right.

I put the the powershell command in the Executable section and the remainder of the the command in the Arguments section, but I don't have it delimited or quoted correctly (I think).

If I execute the above from a DOS command prompt i.e.
c:\>PowerShell (get-content "C:\Some Folder\someFile.txt")| foreach-object{$_+"xxxxx"}|set-content "C:\Some Folder\someFile.txt"

I receive the following error: 'foreach-object{$_+"xxxxx"}' is not recognized as an internal or external command, operable program or batch file.

Suggestions?
Post #1075700
Posted Wednesday, March 9, 2011 12:41 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:32 PM
Points: 13,017, Visits: 10,801
You can run Powershell commands from SQL Server Agent. Is that an option?



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1075826
Posted Thursday, March 10, 2011 11:53 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 9:33 AM
Points: 178, Visits: 626
I suppose it would be an option, but why would I want to? I just want to run a single command line utility, not much different than using the Execute Process Task to run a command line option to unzip a compressed file.

I recently found out solution: in the Arguments box i put:
"(get-content 'C:\YetAnotherFolder\MyFile.txt')| foreach-object{$_+',,,,,,,,,'}|set-content 'C:\YetAnotherFolder\MyFile.txt'"
and it looks like it works perfectly.
Post #1076479
Posted Thursday, March 10, 2011 12:06 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:32 PM
Points: 13,017, Visits: 10,801
BobMcC (3/10/2011)
I suppose it would be an option, but why would I want to?


Well, I don't really see a difference between running a SQL Server Agent job or running an SSIS package.
Both are a means to an end.

Anyway, glad you found a solution.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1076493
Posted Thursday, March 10, 2011 12:28 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 9:33 AM
Points: 178, Visits: 626
Koen Verbeeck (3/10/2011)
BobMcC (3/10/2011)
I suppose it would be an option, but why would I want to?


Well, I don't really see a difference between running a SQL Server Agent job or running an SSIS package.
Both are a means to an end.

Anyway, glad you found a solution.


Koen, On reflection my question about why I would want to, may have sounded snotty and I hope you know I didn't mean it that way. I was genuinely asking why I might want to use an Agent job, in case I was missing something. To explain why I wanted it into an SSIS task is because it's but one task of several related tasks in an SSIS solution I'm building, but I didn't add that as I didn't feel like it was part of the problem.

Thanks for the reply.
Post #1076515
Posted Thursday, March 10, 2011 12:33 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:32 PM
Points: 13,017, Visits: 10,801
Don't worry, I'm not easily offended

It does indeed make sense to incorporate it in SSIS if it is part of a bigger solution.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1076519
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse