How to run Windows Powershell script

I’m trying to run a simple Windows Powershell script from a Nomad job.

task "mytask" {
      driver = "raw_exec"
      config {
        command = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
        args	= ["-File", "${var.service_root_dir}\\task.ps1"]
      }
    }

Then I simply do:

nomad job run -var="service_root_dir=C:\MyServiceRoot" myjob.nomad

This fails to execute and the alloc’s stderr shows the following:

The argument 'C:\MyServiceRoot\task.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.

Of course that file exists and running powershell -File C:\MyServiceRoot\task.ps1 from the Run menu works properly.

I know this is not the main usage of Nomad but it should be plain simple to run a Windows Powershell script.
This is driving me crazy, I’ve spent an entire day trying to get this running.

Any help?

Oh hello again @dg-eparizzi :grinning_face_with_smiling_eyes:

For reference to anyone that lands here in the future, there are further discussion on GitHub.

Sorry, my bad. There was a another client and the job was being scheduled on that one where it didn’t have the file.

1 Like