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)
# Create a unique file name i.e., Process name + date & time in yymmddhhmmss format
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
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|
‘ & ‘|
‘ & ‘|
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;
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;
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 #