Run Powershell from Execute Stage

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
mgsteiner
Premium Member
Premium Member
Posts: 42
Joined: Wed Aug 31, 2011 2:56 am
Location: St. Gallen - CH
Contact:

Run Powershell from Execute Stage

Post by mgsteiner »

Hello Guys,
I 'm having problems when I want to execute a powershell Script remote from an Execute Stage or in a routine using CALL DSEXECUTE.

So, the script ist to execute Db Backups locally on the remote server and it works just fine when I run it from my CMD or PS shell.
Nevertheless, when I do the same execution in Designer does not work.

Does anybody knows I to run a powershell Script in Ds 8.7?,
is there any previous setting to do?

Thanks a lot in advance
Max
MGS
dsetlteam
Premium Member
Premium Member
Posts: 35
Joined: Mon Feb 10, 2014 10:14 pm
Location: USA

Post by dsetlteam »

What is the error that you are getting?

Note - In the Execute Command Activity, prefix powershell.exe before executing your script.

For example, if you want to execute script namely "abcd.ps" then in the command activity put up the following :-

powershell.exe abcd.ps
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Could you post how you call it up from the command line manually and how you call it from DataStage? Please also include the error message.
mgsteiner
Premium Member
Premium Member
Posts: 42
Joined: Wed Aug 31, 2011 2:56 am
Location: St. Gallen - CH
Contact:

Post by mgsteiner »

From the command line (CMD): powershell -File Script1.ps1 (works good)
From Powershell : .\Script1.ps1 (works also good)

In DS Execute Command Stage :
- Command = powershell
- Parameters = -File <scriptpath>\script1.ps1

Error:
---------------
Backup_Test..JobControl (@Execute_Command_1): Executed: powershell -File <scriptpath>\script1.ps1
Reply=0
Output from command ====>
Invoke-Command : An internal error occurred.
At <scriptpath>\script1.ps1:6 char:15
+ invoke-command <<<< -computerName <server1> -Credential $Cred -ScriptBlock {
& '<ServerScriptPath>\script2.ps1' par1 par2 par3}
+ CategoryInfo : InvalidOperation: (:) [Invoke-Command], PSInvali
dOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.I
nvokeCommandCommand
-------------------------

Can it be credentials problems ?
Even if I want to execute a normal (powershell get-help) also does not work.

Any idea?

Thanks a lot in advance
MGS
mgsteiner
Premium Member
Premium Member
Posts: 42
Joined: Wed Aug 31, 2011 2:56 am
Location: St. Gallen - CH
Contact:

Post by mgsteiner »

chulett wrote:Note that this is not the Execute Command stage but rather the Execute stage which is unique to a Windows server install. Not the same animal.
Thanks for the reply, but I dont understant to whom you call animal.

Anyway, Yes, I have Server Edition in a Windows System installed and I see the name of the Stage is Execute Command
MGS
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I removed my post after you answered with your details as I was obviously wrong. I was basing my assumption on the wording in your initial post and the fact that you were on Windows, never mind that it is very early in the morning for me. There is an actual stage named the Command Stage which only comes with Windows and which tends to confuse people. Case in point, me. :wink:

And all I meant by they are "not the same animal" is that the two stages are different.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

mgsteiner wrote:Can it be credentials problems ?
Looks like that may be the case. Check the last post in this thread and see if that helps.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I see you are using a relative path to the command file. The working directory for DataStage commands is set to the project directory, so perhaps it is a path issue. You can copy "script.ps1" to the project directory to test that.
Post Reply