SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help: Execute Process Task --> Powershell Command


Help: Execute Process Task --> Powershell Command

Author
Message
BobMcC
BobMcC
Mr or Mrs. 500
Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)

Group: General Forum Members
Points: 526 Visits: 832
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?
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62202 Visits: 13298
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
BobMcC
BobMcC
Mr or Mrs. 500
Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)

Group: General Forum Members
Points: 526 Visits: 832
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.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62202 Visits: 13298
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
BobMcC
BobMcC
Mr or Mrs. 500
Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)

Group: General Forum Members
Points: 526 Visits: 832
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.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62202 Visits: 13298
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?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search