Running Powershell scripts through Comand Line submitter

I’m trying to wrap my head around the right way to use the Command Line submitter to run Powershell scripts in such a way that they can properly report task progress. I have a dummy script for testing that simply writes out the expected STDOUT:

for ($i=1;$i -le 10;$i++){
    $msg = ("Progress: " + [string]($i*10) + "%")
    #Write-Output $msg --doesn't work
    Write-Host $msg
    #without the following line all the updates are written at once on completion
    [Console]::Out.Flush() 
    Start-Sleep -Seconds 7}

The only way I’ve found where the progress bar in Monitor actually updates is
Execute in Shell: True
Shell to Use: cmd
and then supplying the powershell executable path as the first argument and my script as the second argument.

It seems odd to run a shell within a shell to do this, and it’s making wonder if I should just redefine one of the UNIX shells as Powershell in the submitter repo options instead. The absence of a canned Powershell option seems to suggest this is a bad idea for reasons unknown however.

What’s best practice for running Powershell scripts through deadline while having them able to write their execution progress to the progress bar in Monitor?

You would need to make some changes if you want to do it “the right way.”

If you look at the CommandLine plugin settings, you will see that the path to each shell is configured.
image

You can edit plugins/CommandLine/CommandLine.param to add powershell as an option in this list.

The cmd line submitter has an option for selecting which shell to use, e.g. “cmd”, “ksh”.
You would have to edit scripts/Submission/CommandLineSubmission.py to add powershell to the options in the combo box.
If you look at CommandLine.py::RenderArgument, there is a special case for cmd, where /c is inserted as the first argument. You might want to do something similar for powershell.
Hope this helps.

Thanks, that’s extremely helpful. Is this stuff (the structure of which .py files do what) documented anywhere?

I guess the plugins documentation - Application Plugins — Deadline 10.1.20.3 documentation
overview - Scripting Overview — Deadline 10.1.20.3 documentation
And probably more around those pages.

Thanks!

I also found this blog post very helpful:
https://www.awsthinkbox.com/blog/deadline-entry-points

Yes that’s a nice introduction.