Powershell in TI process

Post Reply
MarenC
Regular Participant
Posts: 436
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Powershell in TI process

Post 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
MarenC
Regular Participant
Posts: 436
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: Powershell in TI process

Post 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);
Post Reply