Page 1 of 1

Attempting to ExecuteCommand() a PS1 Powershell Script

Posted: Thu Dec 12, 2013 6:53 pm
by Kingsley
I am writing a process that calls a script to send out some emails. The script is written in Powershell and uses the built in $smtp.Send() function. http://www.howtogeek.com/120011/stupid- ... -software/
(Trying to avoid 3rd party programs)

I am trying to call the script in the process but process completes with no success.

These are the two approaches I've tried

Code: Select all

cmd = 'cmd /c "powershell \\SERVER\D$\Data\SendEmail.ps1"';
ExecuteCommand(cmd, 1);
and

Code: Select all

cmd = 'cmd /c "\\SERVER\D$\Data\SendEmail.cmd"';
ExecuteCommand(cmd, 1);
SendEmail.cmd

Code: Select all

powershell "\\SERVER\D$\Data\SendEmail.ps1"
Running this cmd script standalone works fine.
If anyone can shed some light or advise a better approach that would be great. Thanks.

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Posted: Thu Dec 12, 2013 7:03 pm
by jim wood
What server os are you running? Have you had any problems with running processes remotely when the data source contains a UNC path? The reason I ask is that I've seen windows server 2008 have issues resolving DNS names if they are setup in a certain way. Have you tried using a physical address on the server instead?

Jim.

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Posted: Thu Dec 12, 2013 7:09 pm
by Kingsley
jim wood wrote:What server os are you running? Have you had any problems with running processes remotely when the data source contains a UNC path? The reason I ask is that I've seen windows server 2008 have issues resolving DNS names if they are setup in a certain way. Have you tried using a physical address on the server instead?

Jim.
Hi Jim,

Yes. I've also tried point it to the physical path.
This is running on Windows server 2008 R2.

I am performing a FileExists() check to ensure TM1 locates the file

Code: Select all

IF(FileExists('D:\Data\SendEmail.cmd') < 1);
   Err = 'File not found';
   ProcessBreak;
ENDIF;

cmd = 'cmd /c "D:\Data\SendEmail.cmd"';
ExecuteCommand(cmd, 1);

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Posted: Thu Dec 12, 2013 7:33 pm
by jim wood
I'm guessing you've been able to execute the script from the command line? Does the user used to start the TM1 service have access to run scripts? For example if it's a the local system account is interact with the desktop enabled?

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Posted: Thu Dec 12, 2013 7:44 pm
by Kingsley
Turned out that my main TM1 server had execution of scripts disabled.
Changed Execution Policy on the server and I was set.
Execute Policy on my client machine was fine. That's why it worked when i ran the script not through TM1.

Code: Select all

Set-ExecutionPolicy RemoteSigned
http://technet.microsoft.com/en-us/libr ... 76949.aspx

Thanks for your time

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Posted: Thu Dec 12, 2013 7:51 pm
by jim wood
I'm glad you managed to find the issue.