PowerShell is Microsoft’s modern powerful scripting and cross-platform solution that runs on Windows, Linux, and macOS #
An IBM Planning Analytics application can be configured to build and run its own PowerShell commands, rather than have external batch files.
To keep everything in one place, you can build a PowerShell command file. You can then run it and then delete it from within a TM1 process. This means the risk of running the wrong batch file is reduced. In this article, we’ll talk you through how some of our consultants use Powershell.
You can create a location to put the temporary files used in the process. This includes a cube in your model to store things such as temporary processing files.
Create a location for temporary objects #
#Create the path for the Output files (the Powershell and Text file)
vDevice= ‘S:’;
vFilePath=’\MyDataBase\TemporaryFiles’;
# Create a unique file name i.e., Process name + date & time in yymmddhhmmss format
vFileProcessID=GetProcessName();
vFileUniqueID=TIMST (Now(), ‘\y\m\d\h\i\s’);
You can then create the full file name for your Powershell file from your components and add the .ps1 file type to tell the operating system to use Powershell to run it.
Create and name your Powershell file #
#Create the Powershell Script filename
vFileType=’.ps1′;
vfile=vDevice|
vFilePath|
vFileProcessID|
‘-‘|
vFileUniqueID|
vFileType;
Then create the commands that you want to automate. In an email generation command, you could set up connection details to the email service. You could then use the ‘Send-MailMessage’ utility and fill out all the switches to use. This could include the SMTP server, who the email is from, who is it to, the Subject, the priority and so on.
Then write the Powershell command lines I want to the ‘.ps1’ file using the echo command.
Write the Powershell command lined using the echo command #
#Create the 3-line PowerShell script in a uniquely identified file using multiple ‘echo’ commands
vCommandLine =’cmd /c “echo ‘|vConnectionManagement|’ >> ‘|vfile|
‘ & ‘|
‘echo ‘|vSendMailCMD|’>>’|vfile|
‘ & ‘|
‘echo’|’exit’|’>>’|vfile|
‘”‘;
ExecuteCommand(vCommandLine,1);
Now we have the file built we can execute it using the Powershell command.
Execute the script #
#Run the Powershell Script
vCommandLine=’cmd /c ‘|’Powershell’| vfile;
ExecuteCommand(vCommandLine,1);
After running the command, we then tidy up by deleting the file that we’ve created in the process.
Tidy up the Powershell file #
# Delete the Powershell Script
vCommandLine=’cmd/c del /Q ‘|vfile;
ExecuteCommand (vCommandLine,1);
One tip that we find useful when developing these processes is to output the text that is being built to a text file. This way, you can see where you need to make a tweak to any command line code for it to behave exactly how you want it to.
Sometimes it’s often that an apostrophe is missed or someone has got the wrong type of quote. You can add a parameter that defaults to ‘No’ but which if changed to ‘Yes’ allows you to check the command lines have generated as they won’t be deleted.
Check your script #
if(pIsThisATest @=’Yes’);
ASCIIOUTPUT(vASCIIOUTPUTfile,vCommandLine);
ENDIF;