Page 1 of 1

Powershell in TI process

Posted: Wed Oct 16, 2019 11:32 am
by MarenC
Hi,

I am trying to create a powershell script to append some files.

I want to run this from a TI process but when I try to run the TI process powershell opens briefly, literally in the blink of an eye and then closes.
More to the point the powershell command does not run. When the powershell window opens I can see there is some red writing as if there is a problem but it closes too quickly before I can read it.

If I run the powershell command in powershell then it runs ok.

I am running the TM1 server as an application.

here is the code:

Code: Select all

ExecuteCommand('Powershell get-childItem "C:\Source\SearchFiles\*.csv" | foreach {[System.IO.File]::AppendAllText("C:\Source\SearchFiles\TestNewFile.csv", [System.IO.File]::ReadAllText($_.FullName))}', 0);
Maren

Re: Powershell in TI process

Posted: Wed Oct 16, 2019 11:58 am
by MarenC
Hi

I managed to solve this by replacing the double quotes in the file path with single quotes.

So now I have:

Code: Select all

vCmd = 'Powershell get-childItem ' |  char(39) | 'C:\EX_MW\SearchFiles\*.csv' | char(39) | '| foreach {[System.IO.File]::AppendAllText(' | char(39) | 'C:\EX_MW\SearchFiles\TestNewFile.csv' | char(39) | ', [System.IO.File]::ReadAllText($_.FullName))}';

ExecuteCommand(vCmd, 0);