If you are familiar with UCS director then you know you can create custom workfow tasks for anything that is JavaScript based. I haven’t seen a means to do this for a PowerShell Script. This is how I figured this out.
Note: Without the help of my co-worker Don Reilly the task would have never worked. He was able to find the correct methods to call for Director.
First thing I did was to clone the in box PowerShell Task.
That brings up a dialog to allow you to choose to clone from tasks that are already there
Now that I have that cloned I can look at the contents of the javascript to find out how to call my script. The script I chose to run is one from another community member. His script gets the last error from the PowerShell agent. I took his script and saved it to my PSA server in d:\director\powershell\director folder and am using this custom work flow task to call this when there is an error.
On to the rest of the setup. Once I cloned the script and then put in the code that I needed with the necessary input’s from the director custom task. I found that the task wouldn’t run. Researching further I found that when you clone the task the PowerShell Task itself is running differently than any other custom task. You can see this behaviour in the screen shot below:
So I then had to goto my resident expert Don Reilly who helped me with discovering the right controller to add to my custom workflow task. I’ll step through in pictures what my work flow in UCS Director 6.5 looks like:
The input for tasks has one property that i chose to just enter in its values. In the LOV values for OutputFormat I entered in the values of XML and JSON.
The method added for the controller is before martial with the following calls to the clopia libs:
importPackage(com.cloupia.feature.powershellAgentController.wftasks); var agentPairs = PSAgentTabularLOV.getAllPowerShellAgentsLOV(); page.setEmbeddedLOVs(id + ".psAgent", agentPairs);
Here is what my script code looks like in the custom task (Powershell is highlighted in blue in the Java script).
For Clarity here is the script: $s = “D:\Director\powershell\director\Get-LastUCSDError.ps1”; if(test-path $s){. $s;}else{“Cannot find $s check path on PowerShell Agent Server”}
// Auto generated to code invoke following task // Task Label: Execute Native PowerShell Command // Task Name: Execute Native PowerShell Command importPackage(java.lang); importPackage(java.util); importPackage(com.cloupia.model.cIM); importPackage(com.cloupia.service.cIM.inframgr); function Execute_Native_PowerShell_Command() { var task = ctxt.createInnerTaskContext("Execute Native PowerShell Command"); // Input 'Label', mandatory=true, mappableTo= task.setInput("Label", input.label); // Input 'PowerShell Agent', mandatory=true, mappableTo=gen_text_input task.setInput("PowerShell Agent", input.psAgent); // Input 'Hide Input in PSA, inframgr logs', mandatory=false, mappableTo=gen_text_input task.setInput("Hide Input in PSA, inframgr logs", input.isHideInput); // Input 'Hide Output in PSA, inframgr logs', mandatory=false, mappableTo=gen_text_input task.setInput("Hide Output in PSA, inframgr logs", input.isHideOutput); // Input 'Commands/Script', mandatory=true, mappableTo=gen_text_input //Changed the command to be hard coded to a script on the var command = '$s = "D:\\Director\\powershell\\director\\Get-LastUCSDError.ps1"; if(test-path $s){. $s;}else{"Cannot find $s check path on PowerShell Agent Server"}'; task.setInput("Commands/Script", command); // Input 'Commands/Rollback Script', mandatory=false, mappableTo=gen_text_input task.setInput("Commands/Rollback Script", ''); // Input 'Output Format', mandatory=false, mappableTo= task.setInput("Output Format", input.outputFormat); // Input 'Depth', mandatory=true, mappableTo= task.setInput("Depth", input.depth); // Input 'Maximum Wait Time', mandatory=true, mappableTo= task.setInput("Maximum Wait Time", input.maxWaitTimeMinutes); // Now execute the task. If the task fails, then it will throw an exception task.execute(); // Now copy the outputs of the inner task for use by subsequent tasks // Type of following output: gen_text_input output.POWERSHELL_NATIVE_COMMAND_RESULT = task.getOutput("POWERSHELL_NATIVE_COMMAND_RESULT"); } // Invoke the task Execute_Native_PowerShell_Command(); <span data-mce-type="bookmark" id="mce_SELREST_start" data-mce-style="overflow:hidden;line-height:0" style="overflow:hidden;line-height:0" ></span>
i can call a locally saved powershell script by using standard native powershell task by saying “poweshell.exe -file Get-LastUCSDError.ps1” which allow me to pass Argument as well.
so i wonder What is the advantage of using this custom task? can you please clarify?
LikeLike
it’s been a while ago since I used UCS Director… Off the top of my Head I don’t recall exactly.
LikeLike