Help: Execute Process Task --> Powershell Command

  • 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?

  • You can run Powershell commands from SQL Server Agent. Is that an option?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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.

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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.

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply