# How to run Windows Powershell script

**URL:** <https://discuss.hashicorp.com/t/how-to-run-windows-powershell-script/32951>\
**Category:** Nomad\
**Tags:** jobs\
**Created:** [December 9, 2021, 11:44am UTC](https://discuss.hashicorp.com/t/how-to-run-windows-powershell-script/32951 "2021-12-09T11:44:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dg-eparizzi](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dg-eparizzi/32/21398_2.png) [@dg-eparizzi](https://discuss.hashicorp.com/u/dg-eparizzi)\
**Post date:** [December 9, 2021, 11:44am UTC](https://discuss.hashicorp.com/t/how-to-run-windows-powershell-script/32951/1 "2021-12-09T11:44:05Z")

</div>

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

```auto
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:

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

```

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![lgfa29](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lgfa29/32/2386_2.png) [@lgfa29](https://discuss.hashicorp.com/u/lgfa29)\
**Post date:** [December 11, 2021, 1:25am UTC](https://discuss.hashicorp.com/t/how-to-run-windows-powershell-script/32951/2 "2021-12-11T01:25:27Z")

</div>

Oh hello again @dg-eparizzi😄

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

> <https://github.com/hashicorp/nomad/issues/11659>
>
> \### Nomad version
> Nomad v1.1.4 (acd3d7889328ad1df2895eb714e2cbe3dd9c6d82)
> 
> \##…# Operating system and Environment details
> Windows 10 Enterprise LTSC
> Version 1809
> OS build 17763.2061
> 
> \### Issue
> Nomad client can't seem to find any binaries. This is running in a single node acting as server and client, installed as a Windows Service and running as "Local System".
> 
> \### Reproduction steps
> Setup a single-node server/client Nomad on Windows 10 running as a Windows Service.
> Try to run a binary using the raw\_exec driver.
> 
> \#### Expected Result
> Binary is found and process executes.
> 
> \#### Actual Result
> Task fails. Allocation shows the following event:
> \`\`\`
> Driver Failure | failed to launch command with executor: rpc error: code = Unknown desc = binary "C:\\\\Program Files\\\\nodejs\\\\node.exe" could not be found
> \`\`\`
> 
> \### Job file (if appropriate)
> \`\`\`
> variable "service\_root\_dir" {
> type = string
> }
> 
> job "logging-system" {
> datacenters = \["dc1"\]
> type = "service"
> 
> group "data-logs-to-influxdb" {
> reschedule {
> attempts = 15
> interval = "1h"
> delay = "30s"
> delay\_function = "exponential"
> max\_delay = "60s"
> unlimited = false
> }
> 
> task "data-logs-to-influxdb" {
> driver = "raw\_exec"
> config {
> command = "C:\\\\Program Files\\\\nodejs\\\\node.exe"
> args = \["${var.service\_root\_dir}\\\\dist\\\\apps\\\\data-logs-to-influxdb\\\\main.js"\]
> }
> }
> }
> }
> \`\`\`
> 
> \### Nomad Client logs (if appropriate)
> \`\`\`
> 2021-12-09T19:40:45.322Z \[WARN\] client.alloc\_runner.task\_runner: some environment variables not available for rendering: alloc\_id=c46de00d-10d0-43dc-6b02-896582f6bf55 task=data-logs-to-influxdb keys=
> 2021-12-09T19:40:54.304Z \[ERROR\] client.driver\_mgr.raw\_exec: destroying executor failed: driver=raw\_exec err="rpc error: code = Unknown desc = executor failed to find process: OpenProcess: The parameter is incorrect."
> 2021-12-09T19:40:54.305Z \[ERROR\] client.driver\_mgr.raw\_exec: error receiving stream from Stats executor RPC, closing stream: alloc\_id=c46de00d-10d0-43dc-6b02-896582f6bf55 driver=raw\_exec task\_name=data-logs-to-influxdb error="rpc error: code = Unavailable desc = transport is closing"
> \`\`\`

---

<div class="post-metadata">

**Author:** ![dg-eparizzi](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dg-eparizzi/32/21398_2.png) [@dg-eparizzi](https://discuss.hashicorp.com/u/dg-eparizzi)\
**Post date:** [December 11, 2021, 1:47pm UTC](https://discuss.hashicorp.com/t/how-to-run-windows-powershell-script/32951/3 "2021-12-11T13:47:11Z")

</div>

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