Attempting to ExecuteCommand() a PS1 Powershell Script

Post Reply
Kingsley
Posts: 21
Joined: Tue Sep 10, 2013 3:34 pm
OLAP Product: TM1
Version: PA 2.0
Excel Version: 2016

Attempting to ExecuteCommand() a PS1 Powershell Script

Post 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.
User avatar
jim wood
Site Admin
Posts: 3960
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Post 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.
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Kingsley
Posts: 21
Joined: Tue Sep 10, 2013 3:34 pm
OLAP Product: TM1
Version: PA 2.0
Excel Version: 2016

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Post 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);
User avatar
jim wood
Site Admin
Posts: 3960
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Post 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?
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Kingsley
Posts: 21
Joined: Tue Sep 10, 2013 3:34 pm
OLAP Product: TM1
Version: PA 2.0
Excel Version: 2016

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Post 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
User avatar
jim wood
Site Admin
Posts: 3960
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: Attempting to ExecuteCommand() a PS1 Powershell Script

Post by jim wood »

I'm glad you managed to find the issue.
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Post Reply