# Powershell command -

**URL:** <https://community.icinga.com/t/powershell-command/1024>\
**Category:** Icinga Director\
**Tags:** commands, icingaweb2, director\
**Created:** [April 25, 2019, 7:14pm UTC](https://community.icinga.com/t/powershell-command/1024 "2019-04-25T19:14:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![csmall](https://community.icinga.com/user_avatar/community.icinga.com/csmall/32/617_2.png) [@csmall](https://community.icinga.com/u/csmall)\
**Post date:** [April 25, 2019, 7:14pm UTC](https://community.icinga.com/t/powershell-command/1024/1 "2019-04-25T19:14:03Z")

</div>

I added powershell as a check command via director and when I execute the command it returns an error saying it can’t find the file or directory.

execvpe(C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe) failed: No such file or directory

What is wrong?

The error displays the single \ but if I preview the command config itself it displays the escaped \ in the path.

I’m confused as I see other posts here that show what I have configured working.

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [April 25, 2019, 8:07pm UTC](https://community.icinga.com/t/powershell-command/1024/2 "2019-04-25T20:07:27Z")

</div>

execvpe is used on Linux, and as such, the service check isn‘t executed on a Windows agent. You can see that by inspecting the check source in Icinga Web’s detail view.

---

<div class="post-metadata">

**Author:** ![csmall](https://community.icinga.com/user_avatar/community.icinga.com/csmall/32/617_2.png) [@csmall](https://community.icinga.com/u/csmall)\
**Post date:** [April 25, 2019, 9:07pm UTC](https://community.icinga.com/t/powershell-command/1024/3 "2019-04-25T21:07:06Z")

</div>

How can I get the command to be executed on the windows host and not Linux? I found your postings showing doing this but I get the error above when I try.

---

<div class="post-metadata">

**Author:** ![log1c](https://community.icinga.com/user_avatar/community.icinga.com/log1c/32/2071_2.png) [@log1c](https://community.icinga.com/u/log1c)\
**Post date:** [April 26, 2019, 5:49am UTC](https://community.icinga.com/t/powershell-command/1024/4 "2019-04-26T05:49:17Z")

</div>

Afaik you just need to set the “Run on Agent” option in the service template to `yes`. Or just create an extra template like `service-check-on-agent` that sets this option and then import it to your specific check/apply rule.

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [April 26, 2019, 6:22am UTC](https://community.icinga.com/t/powershell-command/1024/5 "2019-04-26T06:22:00Z")

</div>

Right. The howto [Windows PowerShell Checks with Icinga2](https://community.icinga.com/t/windows-powershell-checks-with-icinga2/712) uses a command\_endpoint attribute which is abstracted by the Director within the agent settings.

---

<div class="post-metadata">

**Author:** ![csmall](https://community.icinga.com/user_avatar/community.icinga.com/csmall/32/617_2.png) [@csmall](https://community.icinga.com/u/csmall)\
**Post date:** [April 26, 2019, 12:07pm UTC](https://community.icinga.com/t/powershell-command/1024/6 "2019-04-26T12:07:37Z")

</div>

That was it! I can’t beleive I overlooked that setting haha

---

<div class="post-metadata">

**Author:** ![Barney](https://community.icinga.com/user_avatar/community.icinga.com/barney/32/6072_2.png) [@Barney](https://community.icinga.com/u/Barney)\
**Post date:** [June 12, 2023, 12:56pm UTC](https://community.icinga.com/t/powershell-command/1024/7 "2023-06-12T12:56:35Z")

</div>

Also happened in my setup, so maybe it’s worth sharing.

Beware when **importing two service templates with differing agent settings** in the same service.

In short,

- If you define two service templates, one with `run on agent = yes`; the other one with `run on agent = no`;
- and if you create a service (standalone or within a service set) importing both of those templates;

then **pay attention to the order in which you import them**.

If you still want your check to be executed on the (win/linux) agent, the service template with `run on agent = yes` needs to be the last one you declare in the import field (it will overwrite the values from the previous one(s)).

* * *

> **What use case even leads to this problem?!**
>
> One service template is used to set the check command and tresholds and declares `run on agent = yes`.
> 
> The other is used to set some defaults in check execution interval, timeout and so on, which in themselves are actually agent-agnostic.  
> But, you need to set one strict value – agent `yes` or `no`, so for it to be universally applicable, i chose the latter.
