vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Tue Apr 03, 2018 7:52 am
Hi,
I have a ps1 code that could copy files from one folder to another, I'm trying to trigger this via TI process for which I used:
Code: Select all
ExecuteCommand ( 'PowerShell E:\powershell.ps1' , 1);
What I'm trying to achieve now is can we pass the source and target folder names as a parameter via TI?
something like below:
Code: Select all
vDirectory = '\\*****\tm1servers$';
ExecuteCommand ( 'PowerShell E:\tm1servers\powershell.ps1', $name, vDirectory , 1);
I know the above syntax is wrong and doesn't work, but is there any other way?
Last edited by
vino1493 on Thu Feb 21, 2019 5:12 pm, edited 1 time in total.
orlando
Community Contributor
Posts: 167 Joined: Fri Aug 04, 2017 8:27 am
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: Office 365
Post
by orlando » Tue Apr 03, 2018 11:54 am
Hi,
ExecuteCommand has only the two paramaters. One for the CommandLine and one for Wait. So you have to do all your wishes in the CommandLine.
I don't know much about PowerShell, but i would try the following:
vDirectory = '\\*****\tm1servers$';
$Name = WHATEVER_YOU_NEED_HERE'
sCmdPath = 'PowerShell E:\tm1servers\HQ_PS_Performance\Scripts\powershell.ps1';
sCommand = sCmdPath |' ' | $Name |' '| vDirectory;
ExecuteCommand ( sCommand, 1);
Best regards,
orlando
vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Wed Apr 04, 2018 3:13 am
@Orlando Thanks for your reply, this can be done for .exe files not .ps1, I guess I will have to hard code.
orlando
Community Contributor
Posts: 167 Joined: Fri Aug 04, 2017 8:27 am
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: Office 365
Post
by orlando » Wed Apr 04, 2018 7:12 am
@vino1493:
sorry for that. i made a short search yesterday before the reply an found this
http://blog.simonw.se/powershell-functi ... eter-sets/ and thought powershell is able to handle parameters.
best regards,
orlando
Wim Gielis
MVP
Posts: 3120 Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:
Post
by Wim Gielis » Wed Apr 04, 2018 10:30 am
vino1493 wrote: ↑ Wed Apr 04, 2018 3:13 am
@Orlando Thanks for your reply, this can be done for .exe files not .ps1, I guess I will have to hard code.
Where did you read that ?
Best regards,
Wim Gielis
IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==>
121 TM1 articles and a lot of custom code
Newest blog article:
Deleting elements quickly
vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Thu Apr 05, 2018 7:01 am
@Wim Gielis I didn't read it anywhere, tried many trial and errors. Moreover executecommand doesn't accept parameters.
If you have any other thoughts or ideas to it. Please share it here, I would be glad to hear it.
lotsaram
MVP
Posts: 3654 Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland
Post
by lotsaram » Thu Apr 05, 2018 8:29 am
vino1493 wrote: ↑ Thu Apr 05, 2018 7:01 am
@Wim Gielis I didn't read it anywhere, tried many trial and errors. Moreover executecommand doesn't accept parameters.
If you have any other thoughts or ideas to it. Please share it here, I would be glad to hear it.
I don't really know what I am reading here, you have me scratching my head to be honest.
But the clear answer is
of course you can. Yes the ExecuteCommand function only accepts 2 arguments of i) the command line to call and ii) whether to wait for it. But there is nothing to stop you from bundling whatever runtime parameters you want
into the command line string. Obviously in whatever format the relevant command line program requires them.
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Thu Apr 05, 2018 9:19 am
@lotsaram thanks for your comment, could you please share me a sample command line string for power shell scripts!
orlando
Community Contributor
Posts: 167 Joined: Fri Aug 04, 2017 8:27 am
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: Office 365
Post
by orlando » Thu Apr 05, 2018 9:25 am
vino1493 wrote: ↑ Thu Apr 05, 2018 9:19 am
@lotsaram thanks for your comment, could you please share me a sample command line string for power shell scripts!
got a sleeples night because of these parameter and tried this.
My PowerShellscipt:
######################
Param(
[string]$text,
[string]$FilePath
)
$text > $FilePath
######################
My TI Script
#######################
sParam1 = 'WhateverNeededHere';
sPath = 'd:\test\Myfile.txt';
sCommand = 'Powershell D:\TEST\file.ps1 -text '| sParam1 |' -FilePath '| sPath;
ExecuteCommand(sCommand, 0);
#######################
vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Thu Apr 05, 2018 11:01 am
I hope 'text' and 'Filepath' are mere variables and not functions. I altered my code as follows, but it doesn't work. Could you please have a look at it:
TI process
Code: Select all
sServer = 'testd';
sInstance = 'salee';
sCommand = 'PowerShell E:\tm1servers\Scripts\Final.ps1 -Server '| sServer |' -Instance '| sInstance;
ExecuteCommand ( sCommand, 0);
PS1 file:
Code: Select all
Param(
[string]$Server,
[string]$Instance
)
$Server > $Instance
Get-ChildItem "\\$Server\tm1servers$\$Instance\LogFiles\" | where {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Move -Destination "TARGET:\$Server\$Instance\LogFiles\"
And what is the use of '$text > $Filepath' in the version you shared?
Last edited by
vino1493 on Thu Feb 21, 2019 5:13 pm, edited 1 time in total.
orlando
Community Contributor
Posts: 167 Joined: Fri Aug 04, 2017 8:27 am
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: Office 365
Post
by orlando » Thu Apr 05, 2018 12:05 pm
vino1493 wrote: ↑ Thu Apr 05, 2018 11:01 am
And what is the use of '$text > $Filepath' in the version you shared?
This just writes the value of $text to the file specified in $Filepath
Last edited by
orlando on Thu Apr 05, 2018 12:08 pm, edited 1 time in total.
orlando
Community Contributor
Posts: 167 Joined: Fri Aug 04, 2017 8:27 am
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: Office 365
Post
by orlando » Thu Apr 05, 2018 12:08 pm
vino1493 wrote: ↑ Thu Apr 05, 2018 11:01 am
Code: Select all
Get-ChildItem "\\$Server\tm1servers$\$Instance\LogFiles\" | where {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Move -Destination "TARGET:\$Server\$Instance\LogFiles\"
does it copy the files, when you try the values of your variables in the UNC Path?
Get-ChildItem "\\wa01095d\tm1servers$\HQ_PS_Performance\LogFiles\" | where {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Move -Destination "TARGET:\wa01095d\HQ_PS_Performance\LogFiles\
vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Thu Apr 05, 2018 12:46 pm
I would like to get the server and instance from control cube and pass them as a parameter to the power shell script. This script will move the log files from that server\instance\logfiles folder to a share point.
the PS script I use is
Code: Select all
Get-ChildItem "\\$Instance\tm1servers$\HQ_PS_Performance\LogFiles\" | where {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Move -Destination "TARGET:\$Server\$Instance\LogFiles\"
Here variables are $Server and $Instance, I want to create a TI process that could pass the servername and instance name to this script.
Please help me out.
macsir
MVP
Posts: 785 Joined: Wed May 30, 2012 6:50 am
OLAP Product: TM1
Version: PAL 2.0.9
Excel Version: Office 365
Contact:
Post
by macsir » Thu Apr 05, 2018 9:28 pm
| Move -Destination "TARGET:\$Server\$Instance\LogFiles\"
Off the top of my head, MOVE is dos command rather than PS command. Use Move-Item instead.
https://docs.microsoft.com/en-us/powers ... wershell-6
And better to show powershell log when debugging it.
vino1493
Posts: 30 Joined: Tue Mar 14, 2017 12:01 pm
OLAP Product: cognos tm1
Version: 10.2.2
Excel Version: excel 2013
Post
by vino1493 » Thu Feb 21, 2019 5:15 pm
Would like to answer my own question:
Below is the code I used to pass parameters to a PowerShell script. I have not mentioned the variable declaration part.
spath is the variable where I declared the Script's path\filename something like 'E:\scripts\logs.ps1'
Thanks for all your support!
Code: Select all
sPsCmd = '"& {
' |spath | '
-From ' | sFrom | '
-To ' | sTo | '
-cc ' | sCC | '
-Subject ' | ' \" ' | sSubject | ' \"
-Attachments ' | sAttachment | '
-Body ' | ' \" ' | sBody | ' \"
-Priority ' | sPriority | '
-SmtpServer ' | sSmtpServer | '
}"';
# execute command
ExecuteCommand ( 'powershell.exe -command ' | sPsCmd, 1 );
Last bumped by vino1493 on Thu Feb 21, 2019 5:15 pm.